问题
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.
回答1:
Not only in the case that your table is too long to vertically fit into the page (e.g. 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 longtables are not floats, while tables are).
来源:https://stackoverflow.com/questions/29648178/table-unnecessarily-starting-from-next-page-in-latex