端列分隔符与 sidewaystable 奇怪地对齐

端列分隔符与 sidewaystable 奇怪地对齐

我一直无法让文本宽度的横向表格看起来正确。在下面的示例中,末尾列分隔符奇怪地与表格末尾分离,如下所示。

Image displaying how this code renders in Texpad-2

我怎样才能消除这个差距?代码如下:

\documentclass{article}

\usepackage{rotating}
\usepackage{tabularx}
\usepackage{lipsum}

\begin{document}

\begin{sidewaystable}
    \caption{This is my table}
    \centering
    \begin{tabularx}{\textwidth}{|p{0.15\textwidth}|p{0.4\textwidth}|p{0.2\textwidth}|p{0.2\textwidth}|}
        \hline
        \textbf{Column 1} & \textbf{Column 2} & \textbf{Column 3} & \textbf{Column 4}\\ 
        \hline
        Row 1 & \lipsum[2] & some text & more text in here \\
        \hline
        Row 2 & \lipsum[3] & some text & more text in here \\
        \hline
    \end{tabularx}
\end{sidewaystable} 

\end{document}

答案1

tabularx如果环境至少没有一列,则环境是无用的。此处您的表格比(由于 8 个 \tabcolsep)X更宽。以下是代码的正确版本:\textheight

\documentclass{article}

\usepackage{rotating}
\usepackage{tabularx}
\usepackage{lipsum}

\begin{document}

\begin{sidewaystable}
    \caption{This is my table}
\setlength{\extrarowheight}{2pt}
    \centering
    \begin{tabularx}{\textwidth}{|>{\hsize=0.64\hsize}X|>{\hsize=1.68\hsize}X|*{2}{>{\hsize=0.84\hsize}X|}}
        \hline
        \textbf{Column 1} & \textbf{Column 2} & \textbf{Column 3} & \textbf{Column 4}\\
        \hline
        Row 1 & \lipsum[2] & some text & more text in here \\
        \hline
        Row 2 & \lipsum[3] & some text & more text in here \\
        \hline
    \end{tabularx}
\end{sidewaystable}

\end{document} 

enter image description here

相关内容