![如何自动换行宽表?](https://linux22.com/image/368023/%E5%A6%82%E4%BD%95%E8%87%AA%E5%8A%A8%E6%8D%A2%E8%A1%8C%E5%AE%BD%E8%A1%A8%EF%BC%9F.png)
如果我的表格很宽,如何让 LaTeX 换行自动地这样它就不会从页面上掉下来了?
我希望它会被分成几个部分,然后互相叠加显示。
我的桌子是
\documentclass{article}
\begin{document}
\begin{tabular}{*{26}{l}}
a&b&c&d&e&f&g&h&i&j&k&l&m&n&o&p&q&r&s&t&u&v&w&x&y&z\\ \hline
z&y&x&w&v&u&t&s&r&q&p&o&n&m&l&k&j&i&h&g&f&e&d&c&b&a \\
one&two&three&four&five&six&seven&eight&nine&ten&eleven&twelve&
thirteen&fourteen&fifteen&sixteen&seventeen&eighteen&nineteen&twenty&twenty-one&twenty-two&twenty-three&twenty-four&twenty-five&twenty-six
\end{tabular}
\end{document}
相关问题
- 如何才能让非常宽的表格将所有三行包裹在边距内?David 的答案很接近,但
\hline
不起作用。Werner 的答案需要相当多的手动操作。
答案1
这实际上是 Mico 评论的实现
\documentclass{article}
\def\zz#1#2#3{\begin{tabular}[t]{l}#1\\\hline#2\\#3\end{tabular}\linebreak[0]\ignorespaces}
\begin{document}
\begin{center}\setlength\lineskip{10pt}
\zz{a}{z}{one}
\zz{b}{y}{two}
\zz{c}{x}{three}
\zz{d}{w}{four}
\zz{e}{v}{five}
\zz{f}{u}{six}
\zz{g}{t}{seven}
\zz{h}{s}{eight}
\zz{i}{r}{nine}
\zz{j}{q}{ten}
\zz{k}{p}{eleven}
\zz{l}{o}{twelve}
\zz{m}{n}{thirteen}
\zz{n}{m}{fourteen}
\zz{o}{l}{fifteen}
\zz{p}{k}{sixteen}
\zz{q}{j}{seventeen}
\zz{r}{i}{eighteen}
\zz{s}{h}{nineteen}%:-)
\zz{t}{g}{twenty}
\zz{u}{f}{twenty-one}
\zz{v}{e}{twenty-two}
\zz{w}{d}{twenty-three}
\zz{x}{c}{twenty-four}
\zz{y}{b}{twenty-five}
\zz{z}{a}{twenty-six}
\end{center}
\end{document}
答案2
我能找到的最好的东西是不是自动适应沃纳的回答我将如何在实践中运用它。
\documentclass{article}
\usepackage{lipsum}
\usepackage{array} % Used for table wrapping
\usepackage{tabularx} % Used for table wrapping
% Define a new command to hide certain columns of a table
\newcolumntype{H}{>{\setbox0=\hbox\bgroup}c<{\egroup}@{}}
\begin{document}
\lipsum[42]
\newcommand{\hidetableone}[1]{
\begin{tabular}{#1}
a & b & c & d & e & f & g & h & i & j & k & l & m & n & o & p & q & r & s & t & u & v & w & x & y & z\\ \hline
z & y & x & w & v & u & t & s & r & q & p & o & n & m & l & k & j & i & h & g & f & e & d & c & b & a \\
one & two & three & four & five & six & seven & eight & nine & ten & eleven & twelve &
thirteen & fourteen & fifteen & sixteen & seventeen & eighteen & nineteen & twenty &
twenty-one & twenty-two & twenty-three & twenty-four & twenty-five & twenty-six
\end{tabular}
}
\begin{figure}
\centering
\hidetableone{*{0}{H} l | *{9}{l} *{16}{H}}
\hidetableone{*{10}{H} *{7}{l} *{9}{H}}
\hidetableone{*{17}{H} *{6}{l} *{3}{H}}
\hidetableone{*{23}{H} *{3}{l} *{0}{H}}
\caption{This is a caption for a large table.}
\end{figure}
\end{document}
答案3
这也支持booktabs
具有方便语法的规则。
局限性。每行单元格应具有相同的高度。不支持双重规则。
\documentclass{article}
\usepackage{xparse,environ,booktabs}
\ExplSyntaxOn
\NewEnviron{splittabular}[1]
{
\dim_set:Nn \lineskip { 2ex }
\phpirate_splittabular:nV { #1 } \BODY
\par
}
\int_new:N \l__phpirate_rows_int
\seq_new:N \l__phpirate_body_seq
\cs_generate_variant:Nn \seq_set_split:Nnn { c }
\cs_new_protected:Nn \phpirate_splittabular:nn
{
\seq_set_split:Nnn \l__phpirate_body_seq { \\ } { #2 }
\int_zero:N \l__phpirate_rows_int
\seq_map_inline:Nn \l__phpirate_body_seq
{
\int_incr:N \l__phpirate_rows_int
\seq_clear_new:c { \__phpirate_row:n { \l__phpirate_rows_int } }
\seq_set_split:cnn { \__phpirate_row:n { \l__phpirate_rows_int } } { & } { ##1 }
% check for \hline
\tl_clear_new:c { \__phpirate_hline:n { \l__phpirate_rows_int } }
\seq_pop_left:cN { \__phpirate_row:n { \l__phpirate_rows_int } } \l_tmpa_tl
\tl_set_eq:NN \l_tmpb_tl \l_tmpa_tl
\regex_replace_once:nnN { \c{hline|toprule|midrule|bottomrule} } { } \l_tmpa_tl
\seq_put_left:cV { \__phpirate_row:n { \l__phpirate_rows_int } } \l_tmpa_tl
\regex_replace_once:nnN { (\c{hline|toprule|midrule|bottomrule}+).* } { \1 } \l_tmpb_tl
\tl_set_eq:cN { \__phpirate_hline:n { \l__phpirate_rows_int } } \l_tmpb_tl
% end code for \hline
}
\int_step_inline:nnnn { 1 } { 1 } { \seq_count:c { \__phpirate_row:n { 1 } } }
{
\__phpirate_column:nn { #1 } { ##1 }
}
}
\cs_generate_variant:Nn \phpirate_splittabular:nn { nV }
\cs_new_protected:Nn \__phpirate_column:nn
{
\seq_clear:N \l__phpirate_column_seq
\int_step_inline:nnnn { 1 } { 1 } { \l__phpirate_rows_int }
{
\seq_put_right:Nx \l__phpirate_column_seq
{
\exp_not:v { \__phpirate_hline:n { ##1 } }
\seq_item:cn { \__phpirate_row:n { ##1 } } { #2 }
}
}
\begin{tabular}[t]{#1}
\seq_use:Nn \l__phpirate_column_seq { \\ }
\end{tabular}
\linebreak[0]
}
\cs_new:Nn \__phpirate_row:n
{
l__phpirate_row_ \int_eval:n { #1 } _seq
}
\cs_new:Nn \__phpirate_hline:n
{
l__phpirate_hline_ \int_eval:n { #1 } _tl
}
\ExplSyntaxOff
\begin{document}
\begin{center}
\begin{splittabular}{c}
\toprule
a&b&c&d&e&f&g&h&i&j&k&l&m&n&o&p&q&r&s&t&u&v&w&x&y&z\\
\midrule
z&y&x&w&v&u&t&s&r&q&p&o&n&m&l&k&j&i&h&g&f&e&d&c&b&a \\
one&two&three&four&five&six&seven&eight&nine&ten&eleven&twelve&
thirteen&fourteen&fifteen&sixteen&seventeen&eighteen&nineteen&
twenty&twenty-one&twenty-two&twenty-three&twenty-four&twenty-five&twenty-six \\
\bottomrule
\end{splittabular}
\end{center}
\end{document}
它也适用于\hline
。