横向表格:我可以在 \afterpage{} 内使用 \toprule 吗?

横向表格:我可以在 \afterpage{} 内使用 \toprule 吗?

我正在尝试使用景观桌。我偶然发现了问题,我正在尝试修改它以获得更漂亮的表格。我想使用诸如 之类的命令\toprule来绘制水平线。

以下是我的看法:

\documentclass{article}

\usepackage{pdflscape}
\usepackage{afterpage}
\usepackage{capt-of}% or use the larger `caption` package

\usepackage{lipsum}% dummy text
\begin{document}
\lipsum % Text before
\afterpage{%
    \clearpage% Flush earlier floats (otherwise order might not be correct)
    \thispagestyle{empty}% empty page style (?)
    \begin{landscape}% Landscape page
        \centering % Center table
        \begin{tabular}{llll}
            \toprule
            A & B & C & D \\
            \bottomrule
        \end{tabular}
        \captionof{table}{Table caption}% Add 'table' caption
    \end{landscape}
    \clearpage% Flush page
}
\lipsum % Text after
\end{document}

不幸的是它不能编译。

我收到以下错误:

{/usr/local/texlive/2019/texmf-var/fonts/map/pdftex/updmap/pdftex.map}] [2]
LaTeX Font Info:    External font `cmex10' loaded for size
(Font)              <7> on input line 25.
LaTeX Font Info:    External font `cmex10' loaded for size
(Font)              <5> on input line 25.
! Undefined control sequence.
\AP@ ...centering \begin {tabular}{llll} \toprule 
                                                  A & B & C & D \\ \bottomru...
l.25 \end
         {document}
The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Undefined control sequence.
<recently read> \bottomrule 

l.25 \end
         {document}
The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

有什么办法可以解决这个问题吗?我也想以类似的方式使用 tabularx 包。

安德里亚,祝你好运

答案1

在此处输入图片描述

\documentclass{article}

\usepackage{pdflscape}
\usepackage{afterpage}
\usepackage{capt-of}% or use the larger `caption` package
\usepackage{booktabs}%<-----------------------------------ADD
\usepackage{lipsum}% dummy text
\begin{document}
    \lipsum % Text before
%   \afterpage{%
%       \clearpage% Flush earlier floats (otherwise order might not be correct)
%       \thispagestyle{empty}% empty page style (?)
        \begin{landscape}% Landscape page
            \centering % Center table
            \begin{tabular}{lllllllllllllllllll}
                \toprule
                A & B & C & D&&&&&&X&Y&&&&&& \\
                \bottomrule
            \end{tabular}
            \captionof{table}{Table caption}% Add 'table' caption
        \end{landscape}
        \clearpage% Flush page
%   }
    \lipsum % Text after
\end{document}

相关内容