在 Latex 中具有多行和多列的 Longtable

问题描述

我有这张桌子,我想在 Latex 上创建它。我尝试了很多表格包,但对于我使用的每个包,我总是遇到诸如文本超出页面宽度或似乎无法在同一列上创建多行之类的问题。

任何建议都会有所帮助。

enter image description here

\begin{longtabu} to \textwidth {|X|X|X|X|}
    \caption{Data Dictionary}\label{tab:summary}\\ 
    \hline
    \textbf{Tables} &  \textbf{Columns}    &   \textbf{Designation} &   \textbf{Type} \\
    \hline
    \endfirsthead
    \multicolumn{4}{c}%
    {\tablename\ \thetable\ -- \textit{Continued from prevIoUs page}} \\
    \hline
    \textbf{Tables} &  \textbf{Columns}    &   \textbf{Designation} &   \textbf{Type} \\
    \hline
    \endhead
    \hline \multicolumn{4}{r}{\textit{Continued on next page}} \\
    \endfoot
    \hline
    \endlastfoot

\textbf{Building} \newline &
RI Building Ref
(Primary Key)\newline
Building Name\newline
Development Name\newline
Address\newline
Submarket\newline
Latitude\newline
Longitude &
The building reference in Realinflo database\newline
The building name\newline
The development name to which the building belongs,if any.\newline
The building street address\newline
The submarket the building is located at.\newline
The building latitude\newline
The building longitude & 
text\newline
text\newline
text\newline
text\newline
text\newline
float\newline
float\\hline



\end{longtabu} 

解决方法

您可以尝试这种方式,您可以使用 multirow 包中的 multirowrotatebox 包中的 graphicx 的组合。此处,multirow 以这种方式使用:\multirow{<number of rows to span>}{<width>}[<vmove>]{<content>}。如您所见,对于 Building 子表,您使第一列中的第一个单元格跨 7 行,传递 * 为内容的自然宽度,设置 [<vmove>] = [-5ex] 以允许文本移动垂直向下,因为它跨越行而不是相邻单元格中的行数。负值降低文本,而正值升高文本。最后,您将内容作为最后一个参数传递。您使用 rotatebox 作为 \rotate[origin=c]{90}{text} 旋转内容,它相对于初始轴逆时针方向旋转文本 90 度。您在 p{<width>} 环境中使用 longtable 以允许文本换行,其中 width 是列的宽度。您使用 cline{i-j},其中 i 是第一列,j 是水平线跨越的最后一列,在本例中为 cline{2-4}。有了这个,我想你可以尝试剩余的行。请注意,在第一行之后,后续行中的第一个元素留空以允许文本单独跨越多行,因此在这些行中您将看不到 & 之前的文本。

Table

\documentclass{article}
\usepackage{longtable}
\usepackage{multirow,graphicx}

\begin{document}
\begin{longtable}{|p{0.5in}|p{1.2in}|p{1.7in}|c|}
    \caption{Data Dictionary}\label{tab:summary}\\ 
    \hline
    \centering \textbf{Tables}&
    \centering \textbf{Columns}&
    \centering \textbf{Designation}&
    \textbf{Type}\\
    \hline
    \endfirsthead
    \multicolumn{4}{c}%
    {\tablename\ \thetable\ -- \textit{Continued from previous page}} \\
    \hline
    \textbf{Tables} &  \textbf{Columns}    &   \textbf{Designation} &   \textbf{Type} \\
    \hline
    \endhead
    \hline \multicolumn{4}{r}{\textit{Continued on next page}} \\
    \endfoot
    \hline
    \endlastfoot

\multirow{7}{*}[-5ex]{\rotatebox[origin=c]{90}{\textbf{Building}}} &
\centering RI Building Ref
(Primary Key)&
\raggedright  The building reference in database&
text\\

\cline{2-4}

&\centering Building Name&
The building name&
text\\

\cline{2-4}

&\centering Development Name&
The development name to which the building belongs,if any.&
text\\

\cline{2-4}

&\centering Address&
The building street address&
text\\

\cline{2-4}

&\centering Submarket&
The submarket the building is located at.&
text\\

\cline{2-4}

& \centering Latitude&
The building latitude&
float\\

\cline{2-4}

&\centering Longitude &
The building longitude& 
float\\

\hline

\end{longtable}
\end{document}