
我有一個包含多個長文字的表格,無法將它們放入頁面寬度中。我已經找到了一組最佳的列寬度(根據文字寬度進行反覆試驗),但是當我放置內容時,它要么破壞表格,要么不起作用。
後來,我做了一個解決方法,它不再合併行,看起來很糟糕,而且由於我將在論文中使用該表,所以我不能使用它。我的解決方法:
\documentclass{article}
\usepackage{longtable}
\usepackage{multirow}
\usepackage{libertine}
\usepackage[verbose=true,letterpaper]{geometry}
\AtBeginDocument{
\newgeometry{
textheight=9in,
textwidth=6.5in,
top=1in,
headheight=14pt,
headsep=25pt,
footskip=30pt
}
}
\begin{document}
\begin{longtable}[h]{p{1.2cm}p{3.8cm}p{1.8cm}p{2cm}p{1.8cm}p{3.5cm}}
\caption{Sample table}
\label{table:sample} \\
\hline
\textbf{Col 1} & \textbf{Col 2} & \textbf{Slightly loooooooong name} & \textbf{Col 4} & \textbf{Col 5} & \textbf{Col 6} \\ \hline
\endfirsthead
\multicolumn{5}{c}{{\bfseries Table \thetable\ continued from previous page}} \\
\hline
\textbf{Col 1} & \textbf{Col 2} & \textbf{Slightly looooong name} & \textbf{Col 4} & \textbf{Col 5} & \textbf{Col 6} \\ \hline
\endhead
\\ \hline
\multicolumn{5}{r}{{Continued on next page}} \\ \hline
\endfoot
\\ \hline
\endlastfoot
\multirow{2}{*}{lorem ipsum} & voluptatem accusantium doloremque laudantium & 111,111 & 222,222 & 333,333 & Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad \\
& voluptatem accusantium doloremque laudantium & 444,444 & 555,555 & 666,666 \\
\end{longtable}
\end{document}
例如,在附圖中,您可以看到雖然我指定了列寬,但它溢出了。我需要的是,之間的所有數據第 1 欄和第 6 欄應該要調整到這兩列的高度,最好是我指定的列寬度。
當我使用時\makecell
,它看起來像是 3 行的組合。我嘗試過其他方法(寬度多行等),但無法解決我的問題。
答案1
如果我理解得很好,你需要這個:
\documentclass{article}
\usepackage{libertine}
\usepackage[verbose=true,letterpaper]{geometry}
\AtBeginDocument{
\newgeometry{
textheight=9in,
textwidth=6.5in,
top=1in,
headheight=14pt,
headsep=25pt,
footskip=30pt
}
}
\usepackage{tabularray}
\DefTblrTemplate{conthead-text}{normal}{\bfseries Table \thetable\ continued from previous page}
\begin{document}
\begin{longtblr}[
caption={Sample table},
label={table:sample},
]{
colspec={Q[l,1.2cm]Q[l,3.8cm]Q[l,1.8cm]Q[l,2cm]Q[l,1.8cm]Q[l,3.5cm]},
hline{1,2,Z}={solid},
row{1}={font=\bfseries},
rowhead=1,
}
Col 1 & Col 2 & Slightly loooooooong name & Col 4 & Col 5 & Col 6 \\
\SetCell[r=2]{l} lorem ipsum & voluptatem accusantium doloremque laudantium & 111,111 & 222,222 & 333,333 & \SetCell[r=2]{l} Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad \\
& voluptatem accusantium doloremque laudantium & 444,444 & 555,555 & 666,666 \\
Other & lines & just & to & show & the page break\\
Other & lines & just & to & show & the page break\\
Other & lines & just & to & show & the page break\\
Other & lines & just & to & show & the page break\\
Other & lines & just & to & show & the page break\\
Other & lines & just & to & show & the page break\\
Other & lines & just & to & show & the page break\\
Other & lines & just & to & show & the page break\\
Other & lines & just & to & show & the page break\\
Other & lines & just & to & show & the page break\\
Other & lines & just & to & show & the page break\\
Other & lines & just & to & show & the page break\\
Other & lines & just & to & show & the page break\\
Other & lines & just & to & show & the page break\\
Other & lines & just & to & show & the page break\\
Other & lines & just & to & show & the page break\\
Other & lines & just & to & show & the page break\\
Other & lines & just & to & show & the page break\\
Other & lines & just & to & show & the page break\\
Other & lines & just & to & show & the page break\\
Other & lines & just & to & show & the page break\\
Other & lines & just & to & show & the page break\\
Other & lines & just & to & show & the page break\\
Other & lines & just & to & show & the page break\\
Other & lines & just & to & show & the page break\\
Other & lines & just & to & show & the page break\\
Other & lines & just & to & show & the page break\\
Other & lines & just & to & show & the page break\\
Other & lines & just & to & show & the page break\\
Other & lines & just & to & show & the page break\\
Other & lines & just & to & show & the page break\\
Other & lines & just & to & show & the page break\\
Other & lines & just & to & show & the page break\\
\end{longtblr}
\end{document}
答案2
像這樣的東西嗎?
請注意,我已經刪除了該\multirow
指令,因為它在這裡沒有做出任何有用的貢獻。
\documentclass{article}
\usepackage{longtable}
\usepackage{libertine}
\usepackage[verbose=true,letterpaper]{geometry}
\AtBeginDocument{%
\newgeometry{%
textheight=9in, textwidth=6.5in,
top=1in, headheight=14pt, headsep=25pt,
footskip=30pt
}
}
\usepackage{array}
\usepackage{ragged2e} % for '\RaggedRight' macro
\usepackage{booktabs} % for well-spaced horizontal rules
\newcolumntype{P}[1]{>{\RaggedRight\hspace{0pt}}p{#1}}
\hyphenation{looooooo-ong loooo-ong} % choose something sensible
\begin{document}
\begin{longtable}{@{} P{1.2cm} P{3.9cm} *{3}{P{1.8cm}} P{3.9cm} @{}}
%% headers and footers
\caption{Sample table} \label{table:sample} \\
\toprule
\textbf{Col 1} & \textbf{Col 2} &
\textbf{Slightly loooooooong name} &
\textbf{Col 4} & \textbf{Col 5} &
\textbf{Col 6} \\
\midrule
\endfirsthead
\multicolumn{6}{@{}l}{Table \thetable, continued from preceding page} \\
\addlinespace
\toprule
\textbf{Col 1} & \textbf{Col 2} &
\textbf{Slightly looooong name} &
\textbf{Col 4} & \textbf{Col 5} &
\textbf{Col 6} \\
\midrule
\endhead
\midrule
\multicolumn{6}{r@{}}{\footnotesize Continued on next page} \\
\endfoot
\bottomrule
\endlastfoot
%% body of longtable
lorem ipsum &
voluptatem accusantium doloremque laudantium &
111,111 & 222,222 & 333,333 &
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad \\
\addlinespace
&
voluptatem accusantium doloremque laudantium &
444,444 & 555,555 & 666,666 \\
\end{longtable}
\end{document}