将两个单词放在一行中间,让它们之间的空格分开

将两个单词放在一行中间,让它们之间的空格分开

我有这个文件

\documentclass{article}

\begin{document}

\centerline{onlyoneword}
\centerline{sveeeeeeeeeerylongword \qquad shortword}


\end{document}

我想将线置于 的中心\qquad。可以吗?

答案1

制作方框。切勿\centerline在 LaTeX 中使用。

\documentclass{article}
\usepackage{showframe} % just to show the text block margins

\begin{document}

\noindent\makebox[\textwidth]{onlyoneword}\\*
\makebox[\dimexpr.5\textwidth-1em][r]{sveeeeeeeeeerylongword}%
\qquad
\makebox[\dimexpr.5\textwidth-1em][l]{shortword}

% just to have an indicator of the middle of the page
\medskip
\noindent\hfill\vrule height 5pt\hfill\mbox{}
\hrule

\end{document}

在此处输入图片描述

答案2

您可以考虑将文本设置在全宽tabularx。这允许您在相应的单元格内使用换行符(和/或段落):

在此处输入图片描述

\documentclass{article}
\usepackage{tabularx}
\begin{document}

\noindent
\begin{tabularx}{\textwidth}{@{}X@{\qquad}X@{}}
  \multicolumn{2}{c}{onlyoneword} \\
  \raggedleft sveeeeeeeeeerylongword & shortword
\end{tabularx}

% just to have an indicator of the middle of the page
\medskip
\noindent\hfill\vrule height 5pt\hfill\mbox{}
\hrule

\end{document}

答案3

像这样?

\documentclass{article}
\usepackage[T1]{fontenc}

\newlength\mysep \setlength{\mysep}{20pt}%
\newcommand\usemysep{\hspace*{\mysep}}%
\newcommand\hangcenter[2]{%
  \begingroup
  \par
  \centering
  \makebox[0pt][r]{#1\usemysep}%
  \usemysep x\usemysep
  \makebox[0pt][l]{\usemysep #2}%
  \par
  \endgroup
}

\begin{document}

Regular text.

\begin{center}
I want to center the line on the qquad. Is it possible?
I want to center the line on the qquad. Is it possible?
I want to center the line on the qquad. Is it possible?

  AAA

\end{center}

Regular text.

Regular text.

\hangcenter{This is much longer.}{Short}
Regular text.

\end{document}

相关内容