테이블 열이 맞지 않습니다.
Aug 21 2020
나는 tabularx 패키지를 사용하고 있으며 이전 답변에 따라 행이 너무 넓은 테이블을 갖는 문제로 정렬해야합니다. 내 이해는 이것이 텍스트를 감싸고 맞을 것이라는 것입니다. 그러나 실제로 이것은 페이지 너비를 넘어갑니다.
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{array}
\usepackage{wrapfig}
\usepackage{multirow}
\usepackage{tabularx}% for 'tabularx' env. and 'X' col. type
\usepackage{lscape}
\usepackage{listings}
\usepackage{color}
\usepackage{xparse}
\usepackage{placeins}
\usepackage{caption}
\usepackage{enumitem}
\usepackage{booktabs} % for \toprule, \midrule etc macros
\usepackage{ragged2e} % for \RaggedRight macro
\title{examle}
\author{An example from Overleaf}
\begin{document}
\maketitle
\renewcommand{\arraystretch}{1.3}
\listoftables
%% create a derivative column type called 'L':
\newcolumntype{L}{>{\RaggedRight\hangafter=1\hangindent=1.5em}X}
\vspace{1cm}
% \newcolumntype{b}{X}
% \newcolumntype{s}{>{\hsize=.5\hsize}X}
\begin{table*}
\caption{example}
\label{tab:code-example}
\centering
% \begin{tabularx}{\textwidth}{XX}
\begin{tabularx}{1.0\textwidth}{XX}
\toprule % replaced all \hline commands with rules from the booktabs package
\upshape Representation of the code & Code \\
\midrule
Representation 1
& \verb|ID math . ID1 calculateSomethingAwesome ( LIT 100 , LIT 200, LIT 300 )| \\
Another representation name that can be very very long
& \verb|ID math . ID1 calculateSomethingAwesome ( LIT 100 , INTEGER 200, LIT 300 )| \\
Representation 3
& \verb|ID math . ID1 calculateSomethingAwesome ( FLOAT 100 , NUMERIC 200, LIT ID 300 )| \\
\bottomrule
\end{tabularx}
\end{table*}
\end{document}
답변
4 Zarko Aug 21 2020 at 12:55
축어 텍스트는 표에 맞을 수있는 길이입니다. 대신 글꼴 \verb
을 사용 \ttfamily
하고 활성화하면 두 번째 열 cab의 텍스트가 더 많은 줄로 나뉘는 솔루션이 될 수 있습니다 . :

\documentclass{article}
\usepackage{ragged2e}
\usepackage{booktabs, tabularx}
\newcolumntype{L}{>{\RaggedRight\hangafter=1\hangindent=1em}X}
\begin{document}
\listoftables
\begin{table}[ht]
\caption{example}
\label{tab:code-example}
\centering
\renewcommand{\arraystretch}{1.3}
\begin{tabularx}{\textwidth}{@{}>{\hsize=0.8\hsize}L
>{\hsize=1.2\hsize\ttfamily}L
@{}}
\toprule %
Representation of the code & Code \\
\midrule
Representation 1
& ID math.ID1 calculateSomethingAwesome (LIT 100, LIT 200, LIT 300)\\
Another representation name that can be very very long
& ID math.ID1 calculateSomethingAwesome (LIT 100, INTEGER 200, LIT 300) \\
Representation 3
& ID math.ID1 calculateSomethingAwesome (FLOAT 100, NUMERIC 200, LIT ID 300)\\
\bottomrule
\end{tabularx}
\end{table}
\end{document}
3 leandriis Aug 21 2020 at 12:56
문서를 컴파일 할 때 나타나는 경고를 자세히 살펴보면 다음을 찾을 수 있습니다.
\verb may be unreliable inside tabularx
를 사용했지만 테이블이 여백으로 넘쳐나는 이유에 대한 힌트를 이미 제공합니다 tabularx
. 이를 극복하기 위해 이미 프리앰블에로드 된 패키지 \lstinline
의 breaklines=true
옵션 과 함께 사용할 수 있습니다 listings
. 코드에 사용되는 글꼴은 물론 내부의 적절한 옵션을 사용하여 조정할 수 있습니다 \lstset
.
다음 MWE에는를 사용하는 테이블 과 유형 열이 tabularx
있는 일반 테이블의 두 가지 버전이 포함되어 있습니다. 둘 다 텍스트 너비만큼 넓습니다. 예제에서는 불필요한 패키지를 주석 처리하고 각 패키지를 제거한 이유에 대한 설명도 추가했습니다.tabular
p

\documentclass{article}
%\usepackage[utf8]{inputenc} not needed since this is the default with an up-to-date installation
%\usepackage{array} not needed since internally loaded by tabularx
\usepackage{wrapfig}
\usepackage{multirow}
\usepackage{tabularx}
%\usepackage{array,booktabs} Do not load packages more than once.
\usepackage{lscape}
\usepackage{listings}
%\usepackage{color} better to use xcolor instead
%\usepackage{tabularx} Do not load packages more than once.
%\usepackage{multirow} Do not load packages more than once.
%\usepackage{lscape} Do not load packages more than once.
\usepackage{xparse}
\usepackage{placeins}
\usepackage{caption}
\usepackage{enumitem}
%\usepackage{array} Do not load packages more than once.
%\usepackage{wrapfig} Do not load packages more than once.
%\usepackage{booktabs} Do not load packages more than once.
%\usepackage{tabularx} Do not load packages more than once.
\usepackage{ragged2e} % for \RaggedRight macro
\usepackage{booktabs}
\lstset{breaklines=true}
\title{ContextML Tables For the ICSE Submission}
\author{An example from Overleaf}
\begin{document}
\maketitle
\renewcommand{\arraystretch}{1.3}
\listoftables
\begin{table}
\caption{example}
\label{tab:code-example}
\centering
\begin{tabularx}{1.0\textwidth}{XX}
\toprule % replaced all \hline commands with rules from the booktabs package
\upshape Representation of the code & Code \\
\midrule
Representation 1
& {\lstinline|ID math . ID1 calculateSomethingAwesome ( LIT 100 , LIT 200, LIT 300 )|} \\
Another representation name that can be very very long
& {\lstinline|ID math . ID1 calculateSomethingAwesome ( LIT 100 , INTEGER 200, LIT 300 )|} \\
Representation 3
& {\lstinline|ID math . ID1 calculateSomethingAwesome ( FLOAT 100 , NUMERIC 200, LIT ID 300 )|} \\
\bottomrule
\end{tabularx}
\end{table}
\begin{table}
\caption{example}
\label{tab:code-example}
\centering
\begin{tabular}{>{\raggedright\arraybackslash}p{\dimexpr0.35\linewidth-2\tabcolsep}
>{\raggedright\arraybackslash}p{\dimexpr0.65\linewidth-2\tabcolsep}}
\toprule % replaced all \hline commands with rules from the booktabs package
\upshape Representation of the code & Code \\
\midrule
Representation 1
& {\lstinline|ID math . ID1 calculateSomethingAwesome ( LIT 100 , LIT 200, LIT 300 )|} \\
Another representation name that can be very very long
& {\lstinline|ID math . ID1 calculateSomethingAwesome ( LIT 100 , INTEGER 200, LIT 300 )|} \\
Representation 3
& {\lstinline|ID math . ID1 calculateSomethingAwesome ( FLOAT 100 , NUMERIC 200, LIT ID 300 )|} \\
\bottomrule
\end{tabular}
\end{table}
\end{document}