
tabularx を使用して何かをフォーマットし、最初の行に左余白から始まる列と右余白から始まる列があり、次の行はテキスト幅全体にまたがる 1 つの列のみで、テキスト内で改行を許可したいと思います。以下は私のコードです。
\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 行の列が結合されていません。下のコードでこれを実行しようとすると、まず 2 行目と 3 行目のインデントに気づきます。これは、multicolumn コマンドによるものですか? インデントを変更するにはどうすればよいでしょうか? また、\textwidth を p 列の幅として使用すると、これらの行のテキストが右ページ マージンを超えてしまいます。用紙幅からマージンを引いた長さにすると、うまくいきます。これはどうなっているのでしょうか? また、フォーマットの代替案もうれしいです。
答え1
@{}
テーブル コードで既に行ったように、テーブル セルの左右にある小さな (6 pt) 水平方向の空白を削除するには、を使用できます。\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 } \\