tabularx에서 \multicolumn을 사용하면 들여쓰기 및 여백 문제가 발생합니다.

tabularx에서 \multicolumn을 사용하면 들여쓰기 및 여백 문제가 발생합니다.

첫 번째 행에는 왼쪽 여백에서 시작하는 열이 있고 오른쪽에서 시작하는 열이 있고 다음 행은 텍스트에 줄 바꿈을 허용하는 전체 텍스트 너비에 걸쳐 단 하나의 열인 tabularx를 사용하여 형식을 지정하고 싶습니다. 아래는 내 코드입니다.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{multicol}
\usepackage{tabularx}

\begin{document}  
\section{Introduction}

\begin{flushleft}
    \begin{tabularx}{\textwidth}{@{}X @{\extracolsep{\fill}} r @{}}
         Text beginning at left margin & Something at right margin   \\
         \hline
          Here is some text that can get longer and longer until it causes a linebreak eventually & \\
         \textit{Some closing text that would go to the next line soon because of the cell to the right} & \\
    \end{tabularx}
\end{flushleft}


\begin{flushleft}
    \begin{tabularx}{\textwidth}{@{}X @{\extracolsep{\fill}} r @{}}
         Text beginning at left margin & Something at right margin  \\
         \hline
         \multicolumn{2}{p{\textwidth}}{Here is some longer sentence that goes past the original column on the right } \\
         \multicolumn{2}{p{\textwidth}}{\textit{Here is some text that can get longer and longer and longer and longer and longer until it causes a linebreak eventually}} \\
    \end{tabularx}
\end{flushleft}

\end{document}

아래 그림에서 위쪽 부분은 예상한 대로 보이지만 아래쪽 두 행에는 열이 병합되어 있지 않습니다. 맨 아래 코드로 하려고 하면 먼저 2행과 3행의 들여쓰기가 눈에 띕니다. 다중 열 명령에서 나온 것입니까? 들여쓰기를 어떻게 수정하나요? 또한 \textwidth를 p 열의 너비로 사용하면 이 행의 텍스트가 오른쪽 페이지 여백을 초과합니다. 용지 너비에서 여백을 뺀 길이와 같으면 작동합니다. 여기서 무슨 일이 일어나고 있는 걸까요? 또한 형식에 대한 대안 제안에 만족합니다.여기에 이미지 설명을 입력하세요

답변1

@{}테이블 코드에서 이미 수행한 것처럼 테이블 셀의 왼쪽과 오른쪽에 있는 작은(6포인트) 가로 공백을 제거하는 데 사용할 수 있습니다 . 명령이 이 설정을 재정의 하므로 \multicolumn패딩이 다시 추가되어 너비가 ap 유형 열이 되고 \textwidth+2\tabcolsep오른쪽 여백까지 이어집니다. 이 문제를 해결하려면 다음 예제와 같이 명령 @{}에 추가하세요. 여기서는 이 명령이 필요하지 않으므로 \multicolumn제거했습니다 .@{\extracolsep{\fill}}

다음 스크린샷에서 빨간색 선은 페이지 여백을 나타냅니다.

여기에 이미지 설명을 입력하세요

\documentclass{article}
%\usepackage[utf8]{inputenc} % default in an up to date installation
%\usepackage{multicol} % Not related to the \multicolumn command
\usepackage{tabularx}

\begin{document}  
\section{Introduction}

\noindent
    \begin{tabularx}{\textwidth}{@{} X r @{}}
         Text beginning at left margin & Something at right margin  \\
         \hline
         \multicolumn{2}{@{}p{\textwidth}@{}}{Here is some longer sentence that goes past the original column on the right } \\
         \multicolumn{2}{@{}p{\textwidth}@{}}{\textit{Here is some text that can get longer and longer and longer and longer and longer until it causes a linebreak eventually}} \\
    \end{tabularx}

\end{document}

답변2

에서 --https://latex.org/forum/viewtopic.php?t=8352

여기에 이미지 설명을 입력하세요

\multicolumn{2}{@{}p{\textwidth}}{Here is some longer sentence that goes past the 
 original column on the right } \\

관련 정보