아래에 다음 표가 있는데 표가 페이지 너비를 초과하지 않도록 각 열의 텍스트를 줄바꿈하고 싶습니다. 여러 가지 솔루션을 시도했지만 테이블이 축소되는 것 같습니다.
조언을 해주실 수 있나요? 내 코드와 현재 출력 결과에 대한 스크린샷을 포함했습니다.
감사해요!
\documentclass[a4paper,11pt]{article}
\usepackage{tabulary}
\usepackage{adjustbox}
\usepackage{booktabs}
\usepackage{pdflscape,afterpage,booktabs,caption}
\begin{document}
\begin{landscape}% Landscape page
\begin{table}[ht]
\caption{Table test - contents of table exceeds page width}
\setlength\tabcolsep{3pt}
\centering
\small
% your table
\hspace*{-18mm}%
\begin{tabular}{cccc}
\hline\hline
Column 1&Column 2&Column 3\\ [0.5ex]
\hline
Item 1&item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1&item 1, item 1, item 1, item 1, item 1,item 1 ,item 1 ,item 1 ,item 1 ,item 1 ,item 1&item 1, item 1, item 1, item 1\\
Item 1&item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1&item 1, item 1, item 1, item 1, item 1,item 1 ,item 1 ,item 1 ,item 1 ,item 1 ,item 1&item 1, item 1, item 1, item 1\\
Item 1&item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1&item 1, item 1, item 1, item 1, item 1,item 1 ,item 1 ,item 1 ,item 1 ,item 1 ,item 1&item 1, item 1, item 1, item 1\\
Item 1&item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1&item 1, item 1, item 1, item 1, item 1,item 1 ,item 1 ,item 1 ,item 1 ,item 1 ,item 1&item 1, item 1, item 1, item 1\\
\hline
\end{tabular}%
\hspace*{-12mm}%
\label{table:comparison of techniques}
\end{table}
\end{landscape}
\end{document}
답변1
p{}
열 너비를 명시적으로 설정할 수 있는 열 지정자를 사용할 수 있습니다 . 또한 이미 booktabs
패키지를 로드했으므로(두 번이라도!) 실제로 패키지를 사용해야 합니다.
\documentclass[a4paper,11pt]{article}
\usepackage{tabulary}
\usepackage{adjustbox}
\usepackage{booktabs}
\usepackage{pdflscape,afterpage,caption}
\begin{document}
\begin{landscape}% Landscape page
\begin{table}[ht]
\caption{Table test -- contents of table exceeds page width}
\setlength\tabcolsep{3pt}
\centering
\small
% your table
\hspace*{-18mm}%
\begin{tabular}{ l p{60mm} p{60mm} p{60mm} }
\toprule
Column 1&Column 2&Column 3&Column 4\\ [0.5ex]
\midrule
Item 1&item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1&item 1, item 1, item 1, item 1, item 1,item 1 ,item 1 ,item 1 ,item 1 ,item 1 ,item 1&item 1, item 1, item 1, item 1\\
Item 1&item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1&item 1, item 1, item 1, item 1, item 1,item 1 ,item 1 ,item 1 ,item 1 ,item 1 ,item 1&item 1, item 1, item 1, item 1\\
Item 1&item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1&item 1, item 1, item 1, item 1, item 1,item 1 ,item 1 ,item 1 ,item 1 ,item 1 ,item 1&item 1, item 1, item 1, item 1\\
Item 1&item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1&item 1, item 1, item 1, item 1, item 1,item 1 ,item 1 ,item 1 ,item 1 ,item 1 ,item 1&item 1, item 1, item 1, item 1\\
\bottomrule
\end{tabular}%
\hspace*{-12mm}%
\label{table:comparison of techniques}
\end{table}
\end{landscape}
\end{document}
답변2
tabularx
가로 페이지의 텍스트 너비와 행 사이의 간격이 더 넓어진 테이블을 사용하여 몇 가지 개선 사항 :
\documentclass[a4paper,11pt]{article}
\usepackage{tabularx}
\usepackage{booktabs,caption, makecell}
\usepackage{pdflscape,afterpage}
\renewcommand{\theadfont}{\normalsize\bfseries}
\begin{document}
\begin{landscape}% Landscape page
\begin{table}[ht]
\caption{Table test - contents of table exceeds page width}
\centering
\small
\begin{tabularx}{\linewidth}{@{}l*{3}{>{\arraybackslash}X}}
\toprule\midrule[0.5pt]
& \thead{Column 1} & \thead{Column 2} & \thead{Column 3} \\
\midrule
Item 1 & item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1 & item 1, item 1, item 1, item 1, item 1,item 1, item 1, item 1, item 1, item 1, item 1 & item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1 \\
\addlinespace
Item 1 & item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1 & item 1, item 1, item 1, item 1, item 1,item 1, item 1, item 1, item 1, item 1, item 1 & item 1, item 1, item 1, item 1 \\
\addlinespace
Item 1 & item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1 & item 1, item 1, item 1, item 1, item 1,item 1, item 1, item 1, item 1, item 1, item 1 & item 1, item 1, item 1, item 1 \\
\addlinespace
Item 1 & item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1 & item 1, item 1, item 1, item 1, item 1,item 1, item 1, item 1, item 1, item 1, item 1 & item 1, item 1, item 1, item 1 \\
\bottomrule
\end{tabularx}%
\hspace*{-12mm}%
\label{table:comparison of techniques}
\end{table}
\end{landscape}
\end{document}
답변3
이미 로드 중이므로 tabulary
유연한 너비 열의 이점을 활용하여 전체 텍스트 블록 높이를 사용하는 테이블을 생성할 수 있습니다.
\documentclass[a4paper,11pt]{article}
\usepackage{tabulary}
\usepackage{adjustbox}
\usepackage{booktabs}
\usepackage{pdflscape,afterpage,caption}
\begin{document}
\begin{landscape}% Landscape page
\begin{table}[ht]
\caption{Table test - contents of table exceeds page width}
\setlength\tabcolsep{3pt}
\centering
\small
% your table
\hspace*{-18mm}%
\begin{tabulary}{\linewidth}{cCCC}
\toprule
Column 1&Column 2&Column 3\\ [0.5ex]
\midrule
Item 1&item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1&item 1, item 1, item 1, item 1, item 1,item 1 ,item 1 ,item 1 ,item 1 ,item 1 ,item 1&item 1, item 1, item 1, item 1\\
Item 1&item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1&item 1, item 1, item 1, item 1, item 1,item 1 ,item 1 ,item 1 ,item 1 ,item 1 ,item 1&item 1, item 1, item 1, item 1\\
Item 1&item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1&item 1, item 1, item 1, item 1, item 1,item 1 ,item 1 ,item 1 ,item 1 ,item 1 ,item 1&item 1, item 1, item 1, item 1\\
Item 1&item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1&item 1, item 1, item 1, item 1, item 1,item 1 ,item 1 ,item 1 ,item 1 ,item 1 ,item 1&item 1, item 1, item 1, item 1\\
\bottomrule
\end{tabulary}%
\hspace*{-12mm}%
\label{table:comparison of techniques}
\end{table}
\end{landscape}
\end{document}