我需要将文本放在adjustbox
带有minipage
关键字的包中居中(见下面的代码)。我发现可以通过在文本的两侧使用两个\dotfill
或命令来实现这一点。然而令人惊讶的是,它不起作用。\hrulefill
\hfill
我提供了一个最小的工作示例:
\documentclass[12pt]{article}
\usepackage{adjustbox}
\begin{document}
{\bf These work as expected:}\\
\vspace{2ex}
\verb!{\dotfill{Foo}\dotfill}!\\
\adjustbox{fbox,minipage=\textwidth}{\dotfill{Foo}\dotfill}
\vspace{2ex}
\verb!{\hrulefill{Foo}\hrulefill}!\\
\adjustbox{fbox,minipage=\textwidth}{\hrulefill{Foo}\hrulefill}
\vspace{2ex}
\verb!{\hfill{Foo}\hrulefill}!\\
\adjustbox{fbox,minipage=\textwidth}{\hfill{Foo}\hrulefill}
\vspace{5ex}
{\bf These don't:}\\
\vspace{2ex}
\verb!{\hfill{Foo}\hfill}!\\
\adjustbox{fbox,minipage=\textwidth}{\hfill{Foo}\hfill}
\vspace{2ex}
\verb!{\hrulefill{Foo}\hfill}!\\
\adjustbox{fbox,minipage=\textwidth}{\hrulefill{Foo}\hfill}
\end{document}
我有两个问题:
- 如何使我的文本在
\adjustbox
小页面中居中? - 为什么会有这样的行为呢
\hfill
?
答案1
\hfill
您应该在用于避免胶水被吞噬的线的末尾放置一个“标记” ;类似的东西\mbox{}
有效:
\documentclass{article}
\usepackage{adjustbox}
\begin{document}
These work as expected:
\medskip
\verb!{\dotfill{Foo}\dotfill}!\\
\adjustbox{fbox,minipage=\textwidth}{\dotfill{Foo}\dotfill}
\medskip
\verb!{\hrulefill{Foo}\hrulefill}!\\
\adjustbox{fbox,minipage=\textwidth}{\hrulefill{Foo}\hrulefill}
\medskip
\verb!{\hfill{Foo}\hrulefill}!\\
\adjustbox{fbox,minipage=\textwidth}{\hfill{Foo}\hrulefill}
\bigskip\bigskip
These do as well:
\medskip
\verb!{\hfill{Foo}\hfill\mbox{}}!\\
\adjustbox{fbox,minipage=\textwidth}{\hfill{Foo}\hfill\mbox{}}
\medskip
\verb!{\hrulefill{Foo}\hfill\mbox{}}!\\
\adjustbox{fbox,minipage=\textwidth}{\hrulefill{Foo}\hfill\mbox{}}
\end{document}
答案2
\documentclass[12pt]{article}
\usepackage{adjustbox}
\begin{document}
\textbf{These work as expected:}%\\
\vspace{2ex}
\adjustbox{fbox,minipage=\textwidth}{\centering Foo\par}
\end{document}