为什么我的文档会因为旋转包装而侧向失败?

为什么我的文档会因为旋转包装而侧向失败?

我想测试横向表格,并从横向环境开始。但是代码无法编译,我收到错误:

(./content/landscapetable.tex
! LaTeX Error: Something's wrong--perhaps a missing \item.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.6 \begin{center}

这是一个简单的例子:

\documentclass{scrartcl} 
\usepackage[utf8]{inputenc}
\usepackage{tabularx}
\usepackage{caption}
\usepackage{rotating}
\begin{document}
\begin{sideways}
\begin{center}
  \centering 
%  \captionsetup{type=table}
%  \caption{Sehr breite Tabelle.}
\begin{tabularx}{0.8\textheight}{XXX}
\hline
head & head & head \\
\hline
text which is considereably longer than 
the width of the column & 
text which is considereably longer than 
the width of the column & 
text which is considereably longer than 
the width of the column \\
\hline
\end{tabularx}  
\end{center}
\end{sideways}
\end{document}

删除侧面环境,然后进行编译。

编辑:当中心环境被移除,并且居中保留,并且再次引入标题时,会出现另一个标题错误。

\begin{sideways}
  \centering
  \captionsetup{type=table}
  \caption{Sehr breite Tabelle.}
\begin{tabularx}{1.0\textheight}{*{6}{X}}
\hline
head & head & head & head & head & head \\
...
\end{tabularx}  
\end{sideways}

然后错误是

! Missing \endgroup inserted.
<inserted text>
\endgroup
l.5 \caption{Sehr breite Tabelle.}

使用 sidewaystable 可以工作,但这不是我想要的。

答案1

为什么两者都\centering需要center环境?删除后者,示例就可以正常编译。


(基于评论的新解决方案。)

如果您不想旋转标题,为什么要将标题放在环境中sideways?您可以做的是将表格放在正常table环境中,然后将 放在tabularxsideways

\documentclass{scrartcl} 
\usepackage[utf8]{inputenc}
\usepackage{tabularx}
\usepackage{caption}
\usepackage{rotating}
\begin{document}
\begin{table}
  \centering 
  \captionsetup{type=table}
  \caption{Sehr breite Tabelle.}
  \begin{sideways}
  \begin{tabularx}{0.8\textheight}{XXX}
    \hline
    head & head & head \\
    \hline
    text which is considereably longer than 
    the width of the column & 
    text which is considereably longer than 
    the width of the column & 
    text which is considereably longer than 
    the width of the column \\
  \hline
  \end{tabularx}
  \end{sideways}
\end{table}
\end{document}

在此处输入图片描述

另一方面,我认为最好使用sidewaystable,并将标题也旋转。在阅读标题和阅读表格之间必须翻页会很尴尬和不方便。

相关内容