
Gostaria de formatar algo usando tabularx onde a primeira linha tem uma coluna começando na margem esquerda e outra começando na direita, e as linhas seguintes sendo apenas uma coluna abrangendo toda a largura do texto, permitindo quebras de linha no texto. Abaixo está meu código:
\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}
Na imagem abaixo, a parte superior parece o esperado, porém, as duas linhas inferiores não têm suas colunas mescladas. Quando tento fazer isso com o código inferior, noto primeiro um recuo na 2ª e 3ª linha. Isso vem do comando multicolumn? Como modifico o recuo? Além disso, o texto nessas linhas excede a margem direita da página ao usar \textwidth como a largura da coluna p. Se eu tiver um comprimento igual à largura do papel menos as margens, funciona. O que está acontecendo aqui? Além disso, estou feliz com sugestões alternativas de formatação.
Responder1
Você pode usar @{}
para remover o pequeno espaço em branco horizontal (6 pt) à esquerda e à direita de uma célula da tabela, como já fez no código da tabela. Como o \multicolumn
comando substitui essa configuração, o preenchimento é adicionado novamente, resultando em uma coluna do tipo ap que é tão larga quanto \textwidth+2\tabcolsep
e vai até a margem direita. Para superar isso, adicione @{}
ao seu \multicolumn
comando conforme mostrado no exemplo a seguir. Também removi @{\extracolsep{\fill}}
porque este comando não é necessário aqui.
Na captura de tela a seguir, as linhas vermelhas indicam as margens da página:
\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}
Responder2
De --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 } \\