我有一张表格,由于文本太长,它不适合放在(横向)页面上。请考虑此代码作为示例(实际文档中使用的包,因此将它们包含在内以避免兼容性问题):
\documentclass[a4paper,12pt]{article}
\usepackage{natbib}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{lmodern}
\usepackage{csquotes}
\usepackage[ddmmyyyy]{datetime}
\usepackage{color}
\usepackage{enumerate}
\usepackage{enumitem}
\usepackage{float}
\usepackage{lscape}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{mathtools}
\begin{document}
\begin{landscape}
\begin{table}[]
\begin{tabular}{@{}|c|c|c|c|c|c|c|c|c|@{}}
\toprule
\textbf{header 1} & \multicolumn{2}{c|}{header 2} & \multicolumn{4}{c|}{header 3} & \multicolumn{2}{c|}{header 4}\\ \midrule
\textbf{tex1} & foo & text here & some more, longer text &really long text here that makes table wide&text&longer text&more text& text that is also really long \\ \bottomrule
\end{tabular}
\caption{individuals reactions by actor-specific characteristics}
\label{tab:individuals reactions by actor-specific characteristics}
\end{table}
\end{landscape}
\end{document}
我无法获得其他解决方案像这个由于我的代码中的-line,可以使用p{width}
或在其他地方提到的方法。resizebox
\begin{tabular}{@{}|c|c|c|c|c|c|c|c|c|@{}}
由于我对 LaTeX 还不太熟悉,有人能告诉我最好的解决方案吗?非常感谢,祝一切顺利。
答案1
使用后tabularx
您可以获得:
\documentclass[a4paper,12pt]{article}
\usepackage{lscape}
\usepackage{booktabs, tabularx}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\begin{document}
\begin{landscape}
\begin{table}
\setlength\tabcolsep{3pt}
\begin{tabularx}{\linewidth}{cccCCcccC}
\toprule
\textbf{header 1} & \multicolumn{2}{c}{header 2} & \multicolumn{4}{c}{header 3} & \multicolumn{2}{c}{header 4}\\
\cmidrule(l){1-1}\cmidrule(l){2-3}\cmidrule(l){4-7}\cmidrule(l){8-9}
\textbf{tex1} & foo & text here & some more, longer text &really long text here that makes table wide&text&longer text&more text& text that is also really long \\ \bottomrule
\end{tabularx}
\caption{individuals reactions by actor-specific characteristics}
\label{tab:individuals reactions by actor-specific characteristics}
\end{table}
\end{landscape}
\end{document}
答案2
最接近我想要的解决方案是使用\newcolumntype{P}
然后手动定义列宽(见下文)。
\documentclass[a4paper,12pt]{article}
\usepackage{float}
\usepackage{lscape}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{array}
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\begin{document}
\begin{table}[H]
\begin{tabular}{|P{2cm}||P{0.8cm}|P{0.8cm}|P{0.8cm}|P{0.8cm}|P{0.8cm}|P{0.8cm}|P{0.8cm}|P{0.8cm}|P{0.8cm}||}
\hline
\textbf{position} & \multicolumn{2}{P{2cm}|}{text no. one} & \multicolumn{4}{c|}{text} & \multicolumn{2}{c|}{text no. two} \\ \hline
\textbf{other} & \multicolumn{2}{c|}{-} & \multicolumn{2}{c|}{towards no. one} & \multicolumn{2}{c|}{away from no. one} & \multicolumn{2}{c|}{-} \\ \hline
\textbf{two line text} & low & high & low & high & low & high & low & high \\ \hline
\end{tabular}
\end{table}
\end{document}