我正在尝试弄清楚如何定位和居中事物。
这里我并排放置了两个非常大的 PDF。我将它们缩小到当前大小并尝试将它们居中:
\documentclass{article}
\usepackage[margin=1in,showframe]{geometry}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\centering
\begin{figure}
%
\centering
\begin{minipage}[c][1\totalheight][t]{0.45\textwidth}%
\begin{center}
{\includegraphics[scale=0.085]{diagrams/pdf/square.pdf}}
\end{center}
\caption{I sit hard up against the left margin}
\end{minipage}\hfill{}%
%
\begin{minipage}[c][1\totalheight][t]{0.45\textwidth}%
\begin{center}
{\includegraphics[scale=0.085]{diagrams/pdf/square.pdf}}
\end{center}
\caption{I hang over the edge of the right margin}
\end{minipage}\hfill{}%
%
\end{figure}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{document}
它可以工作,但它只悬在右边距上,因此它不是真正居中的。如果我进一步缩小它们,到一定程度时就不再是问题了,但假设将它们缩小到小于 % 是不切实际的0.085
,你只是希望它看起来更像这样:
请注意,相对于两个图形的位置,页面是如何完美对称的,并且多余的部分在边距之间均匀分布?
我该如何实现这一点?我以为使用minipage
可以解决这个问题,但我想不是。
答案1
以下是使用这个答案。
\documentclass{article}
\usepackage[margin=1in,showframe]{geometry}
\usepackage{graphicx}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\centering
\begin{figure}
%
\hspace{-0.025\textwidth}\makebox[1.05\textwidth][c]{
\noindent\begin{minipage}[t,outer sep=0]{0.45\textwidth}%
\begin{center}
{\includegraphics[width=\textwidth]{example-image-a}}
\end{center}
\caption{I sit hard up against the left margin}
\end{minipage}\hfill%
%
\begin{minipage}[t,outer sep=0]{0.45\textwidth}%
\begin{center}
{\includegraphics[width=\textwidth]{example-image-b}}
\end{center}
\caption{I hang over the edge of the right margin}
\end{minipage}}%
%
\end{figure}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{document}
输出:
PS1:如果命令\makebox
创建一个框,将在文本宽度后添加...因此将其减少一半1.05\textwidth
0.05\textwidth
\hspace{-0.025\textwidth}
PS2:对小页面使用适当的宽度,但要注意外部分隔符,以防您将使用命令的整个宽度\makebox
。
编辑:更好的方法:
\documentclass{article}
\usepackage[margin=1in,showframe]{geometry}
\usepackage{graphicx}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\centering
\begin{figure}
%
\noindent\makebox[\textwidth][c]{
\noindent\begin{minipage}[t,outer sep=0]{0.525\textwidth}%
\begin{center}
{\includegraphics[width=\textwidth]{example-image-a}}
\end{center}
\caption{I sit hard up against the left margin}
\end{minipage}\hspace{0.5cm}%
%
\begin{minipage}[t,outer sep=0]{0.525\textwidth}%
\begin{center}
{\includegraphics[width=\textwidth]{example-image-b}}
\end{center}
\caption{I hang over the edge of the right margin}
\end{minipage}}%
%
\end{figure}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{document}