简体   繁体   中英

Table unnecessarily starting from next page in latex

How can I stop my table in latex to start unnecessarily from next page leaving a huge space in previous page? How can I force to start just after the heading. Here is my code:

I am using packages:

\usepackage{tabularx,ragged2e,booktabs,caption},
\usepackage{float}

and the code for my table is:

\begin{table}[H]
\begin{tabular}{| l| l }
$.$ & Matches any character.\\ 
$*$ & Matches zero or more instances of the previous pattern item.\\
$+$ & Matches one or more instances of the previous pattern item.\\
$?$ & Matches zero or one instances of the previous pattern item.\\
$( )$ & Groups a subpattern. The repetition and alternation operators apply to the preceding subpattern.\\
$|$ & Alternation.\\
$[ ]$ & Delimit a set of characters. Ranges are specified as [x-y].\\
\textasciicircum & Anchor the pattern to the beginning of the string. Only when first.\\
\$ & Anchor the pattern to the end of the string. Only when last.\\
\end{tabular}
\end{table}

I tried [!ht] , [!htp] and [htpb] nothing of that sort works instead the table vanishes.

Not only in the case that your table is too long to vertically fit into the page (eg below a header or some text paragraph), you can switch from the float approach to:

%\begin{center}
\begin{longtable}{|l|l}
    %
  \endfirsthead
    %
  \endhead
    %
  \endfoot
    %
  \endlastfoot
    $.$ & Matches any character.\\ 
    $*$ & Matches zero or more instances of the previous pattern item.\\
    $+$ & Matches one or more instances of the previous pattern item.\\
    $?$ & Matches zero or one instances of the previous pattern item.\\
    $( )$ & Groups a subpattern. The repetition and alternation operators apply to the preceding subpattern.\\
    $|$ & Alternation.\\
    $[ ]$ & Delimit a set of characters. Ranges are specified as [x-y].\\
    \textasciicircum & Anchor the pattern to the beginning of the string. Only when first.\\
    \$ & Anchor the pattern to the end of the string. Only when last.\\
\end{longtable}
%\end{center}

When compiled, this looks exactly like your table , provided you include \\usepackage{longtable} in your preamble (and longtable s are not floats, while table s are).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM