
これは愚かな質問に聞こえるかもしれませんが、私は LaTeX の初心者です。
\begin{table}[H]
\centering
\begin{tabular*}{\textwidth}{|c|}
\hline
\begin{tabular}[c]{@{}l@{}}
\textbf{\textbf{Description sommaire}}:
\end{tabular}
\\ \hline
\end{tabular*}
\end{table}
テーブルをページ幅に強制的に収めようとしています。 を使用しました{tabular*}
が、うまくいきました。しかし、今度は境界線に問題があります。左の境界線は正常に表示されますが、右の境界線は誤って表示されます。
表には列が 1 つしかなく、右の境界線を表の右端に表示したいのですが、どうすればよいですか?
答え1
tabular*
テーブルをテキスト幅全体に拡張する機能を利用するには、特別な構文に従う必要があります。必要な構文は次のとおりです。
\begin{table}[htbp]
\centering
\begin{tabular*}{\textwidth}{|c|@{\extracolsep{\fill}}c|}
\hline
\textbf{\textbf{Description sommaire}}: & \\ \hline
\end{tabular*}
\end{table}
それ以外の場合は、より一般的なtabularx
環境(私が推奨)を使用してください。
\begin{table}[htbp]
\centering
\begin{tabularx}{\textwidth}{|c|X|}
\hline
\textbf{\textbf{Description sommaire}}: & \\ \hline
\end{tabularx}
\end{table}
これにより、同じ結果が得られ、さらにテキストの折り返しも追加されます。
答え2
フレーム付きのセクションのようなタイトルを作ろうとしているのですか?
フロート ( table
) を作成するのは、考えられる限り最悪のアイデアです。これにより、タイトルがどこにでも移動される可能性があります。[H]
オプションを使用してフロートがフロートしないようにしても、table
環境はまったく不要です。テーブルのインデントを避けて垂直スペースを追加するために使用している可能性がありますが、フロートを使用しない方がうまく解決できます (それぞれ、 および などの\noindent
垂直スペース コマンドを使用する\bigskip
か、 を\parindent
0pt および\parskip
以上に設定してください)。
ネストされた表形式も意味がありません。1 つの (単純な) 表形式で十分です。または、 、 、または minipage 環境として、行幅からフレーム ボックスが使用するスペースを減算できるフレーム ボックス ( ) を\fbox{}
セクション の再定義に含めるか、または代わりに、またはとして非常に構成可能なボックス化パッケージを使用するか、またはボックスを作成せずに、単に \vrules と \hrules をいくつか記述します。\makebox
\parbox
mdframed
tcolorbox
例では、多くの選択肢のうち 5 つを示しています。満足できるものを 1 つ選んでください。
\documentclass{article}
% Padding of \fbox{}
\setlength\fboxsep{.5em}
% Some dummy text between solutions, just to see the layout
\def\loreipsum{Lorem ipsum dolor sit amet, consectetur adipiscing
elit. Fusce elit lectus, dapibus eget pellentesque eu, ultricies
vel turpis. Cras quis convallis nibh.}
% for solution 2 only
\makeatletter
\newcommand\fsection{\@startsection{section}{1}{\z@}%
{1em}{1em}{\bfseries\framedbox}}
\makeatother
\newcommand*\framedbox[1]{\noindent%
\fbox{\parbox{\dimexpr\columnwidth-2\fboxsep}{#1}}}
% for solution 5 only
\usepackage{mdframed}
\begin{document}
\loreipsum
% solution 1
\bigskip\hrule
\noindent
\vrule height 12pt depth 6pt width 0.4pt
{ \bfseries Description sommaire}\hfill\vrule
\hrule\bigskip
\loreipsum
% solution 2
\fsection*{Description sommaire}
\loreipsum
% solution 3
\bigskip
\noindent\fbox{\makebox[\dimexpr\linewidth-2\fboxsep-2\fboxrule][l]
{\textbf{Description sommaire}}}\bigskip
\loreipsum
% solution 4
\bigskip
{\renewcommand\arraystretch{1.4}\setlength\tabcolsep{.5em}
\noindent\begin{tabular}%
{|p{\dimexpr\linewidth-2\tabcolsep-2\arrayrulewidth}|}\hline
\textbf{Description sommaire} \\\hline
\end{tabular}}
\bigskip
\loreipsum
% solution 5
\begin{mdframed}
\textbf{Description sommaire}:
\end{mdframed}
\loreipsum
\end{document}