如何自动将文档中每个小页面内容的最后一行居中

如何自动将文档中每个小页面内容的最后一行居中

考虑以下代码:

\documentclass{book}
\usepackage{lipsum}

\begin{document}
\thispagestyle{empty}
\Large
\begin{center}
\begin{minipage}{5.65in} %\leftskip\fill\rightskip-\leftskip\parfillskip\stretch{2}% 
\textbf{I would like to center the last line of the content of this minipage. The next minipage accomplishes this only for that minipage.}
\end{minipage}

\vspace*{25pt}

\fbox{
\begin{minipage}{5.65in}\leftskip\fill\rightskip-\leftskip\parfillskip\stretch{2}% 
\textbf{By inserting the above string of commands next to $\{$5.65$\}$ accomplishes the task for this particular minipage.}
\end{minipage}
}

\vspace*{45pt}

\begin{minipage}{5.65in} %\leftskip\fill\rightskip-\leftskip\parfillskip\stretch{2}% 
\textbf{But I would like to automatically center the last line of the contents of a minipage environment---for all such minipages in a document---without continually having to insert the aforesaid series of commands that does it only for the minipage to which it is applied.}
\end{minipage}

\vspace*{25pt}

\begin{minipage}{5.65in} %\leftskip\fill\rightskip-\leftskip\parfillskip\stretch{2}% 
\textbf{But I would like to automatically center the last line of the contents of a minipage environment---for all such minipages in a document---without continually having to insert the aforesaid series of commands that does it only for the minipage to which it is applied.}
\end{minipage}

\vspace*{25pt}

\begin{minipage}{5.65in} %\leftskip\fill\rightskip-\leftskip\parfillskip\stretch{2}% 
\textbf{But I would like to automatically center the last line of the contents of a minipage environment---for all such minipages in a document---without continually having to insert the aforesaid series of commands that does it only for the minipage to which it is applied.}
\end{minipage}

\end{center}
\end{document}

它产生输出:

在此处输入图片描述

我想自动将给定文档中每个小页面的最后一行居中。这一系列命令\leftskip\fill\rightskip-\leftskip\parfillskip\stretch{2}%仅针对应用它的小页面实现居中。

如果一个文档有 100 个这样的小页面,我希望能够避免应用上述一系列命令 100 次。

问题:(i)如何才能自动将小页面输出的最后一行居中,而不必对文档中的每个小页面环境应用上述一系列命令?(ii)此外,如果在众多小页面中有一个小页面我不希望其最后一行居中,我如何才能防止对该特定小页面应用居中?

谢谢。

答案1

您可以使用您的设置和一个可选参数(小页面的宽度,默认值= 5.65 英寸)定义一个新命令

在这种情况下\Xmini[<width>]{<content>}将插入请求的minipage最后一行content居中。

如果在特殊情况下您不想使用它,请使用普通小页面。

b

\documentclass{book}
\usepackage{lipsum}


\newcommand{\Xmini}[2][5.65in]{% added <<<<<<<<<<<<<<<<<<<<<<<<<<<
\begin{minipage}{#1}\leftskip\fill\rightskip-\leftskip\parfillskip\stretch{2}%
#2%
\end{minipage}  
}

\begin{document}
    \thispagestyle{empty}
    \Large
    \begin{center}
        \begin{minipage}{5.65in} %\leftskip\fill\rightskip-\leftskip\parfillskip\stretch{2}% 
            \textbf{I would like to center the last line of the content of this minipage. The next minipage accomplishes this only for that minipage.}
        \end{minipage}
        
        \vspace*{25pt}
        
        \fbox{
            \begin{minipage}{5.65in}\leftskip\fill\rightskip-\leftskip\parfillskip\stretch{2}% 
                \textbf{By inserting the above string of commands next to $\{$5.65$\}$ accomplishes the task for this particular minipage.}
            \end{minipage}
        }
        
        \vspace*{45pt}
        
        \Xmini{%
            \textbf{But I would like to automatically center the last line of the contents of a minipage environment---for all such minipages in a document---without continually having to insert the aforesaid series of commands that does it only for the minipage to which it is applied.}
        }
        
        \vspace*{25pt}
        
            \Xmini[4in]{%
         \small \emph{But I would like to automatically center the last line of the contents of a minipage environment---for all such minipages in a document---without continually having to insert the aforesaid series of commands that does it only for the minipage to which it is applied.}
        }
        
        \vspace*{25pt}
        
    \Xmini[3in]{%
            \sffamily But I would like to automatically center the last line of the contents of a minipage environment---for all such minipages in a document---without continually having to insert the aforesaid series of commands that does it only for the minipage to which it is applied.
    }
        
    \end{center}
\end{document}

答案2

 \g@addto@macro\@minipagerestore{\leftskip\fill\rightskip-\leftskip\parfillskip\stretch{2}}

相关内容