
文章の一部を中央揃え(左揃え、右揃えも)したい内で1 つの段落にまとめるには、Word で と簡単にできます[newline] + [center this line] + [newline]
。ただし、LaTeX では、centering
コマンドは段落全体に影響し、グループのみに影響を及ぼすには、\par
そのグループの先頭と末尾に が必要です。一方、center
環境は垂直方向のスペースを追加します。私のニーズに合うコマンドがあることはわかっていますcenterline
が、「左揃え」や「右揃え」に相当するものはないようです。MWE は次のとおりです。
\documentclass{article}
\begin{document}
I want to center\\
"This piece of text"\\
within this paragraph.
I don't want to break the
{\par\centering paragraph like\par}
this.
How to achieve the effect\\
\centerline{without \texttt{centerline}}\\
or \begin{center}
the \texttt{center} environment?
\end{center}
\end{document}
答え1
新しい答え
指摘したように@カンパ対応するものを自分で定義する必要はありません。それらはすでにLaTeXに含まれており、 および\leftline
と呼ばれています\rightline
。したがって、次のように使用できます。
\documentclass[]{article}
\begin{document}
\hsize=5cm % just so that line breaks are a bit earlier
This is some longish text that is long and needs me to centre some
material\\
\centerline{here is center}
Also I'd like to display some stuff to the left\\
\leftline{here is left}
and to put something on the right\\
\rightline{here is right.}
\end{document}
古い回答
後世のために保存します。
左揃えと右揃えの対応するものを定義すると、次のようになります。 1 行より幅の広くないコンテンツのみが意図したとおりに機能し、内部では\@@line
自動改行は行われないことに注意してください。
もしあなたが疑問に思っているなら、\hss
接着剤はh水平にsトレンチコートまたはs指定されたスペースを埋めるのに必要なだけ縮小します (は現在の と同じ幅、つまりテキストの幅になる\@@line
単一の です)。\hbox
\hsize
\documentclass[]{article}
\makeatletter
\newcommand\leftalignline[1]{\@@line{#1\hss}}
\newcommand\rightalignline[1]{\@@line{\hss#1}}
\makeatother
\begin{document}
\hsize=5cm % just so that line breaks are a bit earlier
This is some longish text that is long and needs me to centre some
material\\
\centerline{here is center}
Also I'd like to display some stuff to the left\\
\leftalignline{here is left}
and to put something on the right\\
\rightalignline{here is right.}
\end{document}