围绕居中单词对齐段落

围绕居中单词对齐段落

我想对齐/缩进一个段落,使特定的单词或短语位于页面的水平中心,但我不知道从哪里开始实现它(也许通过计算段落第一行的自定义缩进或使用框技巧,但怎么做?)。有什么建议吗?

例子: 例子

MWE 游乐场:

\documentclass{article}

\usepackage{blindtext}

\newcommand*\alignword[1]{%
    % do fancy alignment tricks here
    \textbf{#1}%
}

\begin{document}

In this paragraph, the word \alignword{center} should be horizontally centered
on the page, with the rest of the paragraph flowing around it.

Like this (dirty imprecise hack, the amount would be different for each paragraph):

\begingroup
\setlength{\parindent}{3em}
In this paragraph, the word \textbf{center} should be horizontally centered
on the page, with the rest of the paragraph flowing around it.
\endgroup

Likewise in the following paragraph:

\blindtext[1] \alignword{Word} \blindtext[1]

\end{document}

答案1

在此处输入图片描述

\documentclass{article}

\usepackage{blindtext}

\newcommand*\alignword[1]{%
    \sbox0{\textbf{#1}}%
    \parfillskip\dimexpr.5\linewidth-.5\wd0\relax
    \copy0\par
    \nopagebreak
    \vspace{-\baselineskip}
    \noindent\hspace*{\dimexpr.5\linewidth+.5\wd0\relax}}


\begin{document}

In this paragraph, the word \alignword{center} should be horizontally centered
on the page, with the rest of the paragraph flowing around it.


\blindtext[1] \alignword{Word} \blindtext[1]

\end{document}

相关内容