图像对齐

图像对齐

是否可以将图像上的一个点与图像环境之外的标记对齐?

假设我有一张图片和一个段落。是否可以在段落中设置一个标记 X,并将图片的中心与该标记对齐(例如,在 X 右侧 1 厘米处)?

如果不是,我如何将图像定位在中心+1cm而不是中心?

编辑

我发现我可以像这样改变

  \quad \includegraphics

以实现运动。

答案1

是的,您可以保存页面上的 x(和 y)坐标,并在其他地方的计算中使用它。在 pdfLaTeX 下,您可以使用zref模块savepos执行可扩展计算:

在此处输入图片描述

\documentclass{article}
\usepackage{graphicx,zref-savepos}
\setlength{\parindent}{0pt}% Just for this example
\begin{document}

Exact centre of text block:

\rule{.5\textwidth}{1pt}

\begin{center}
  \includegraphics[height=3\baselineskip]{example-image-a}
\end{center}

\rule{.5\textwidth}{1pt}

\hfill\includegraphics[height=3\baselineskip]{example-image-b}\hfill\mbox{}

\hrulefill

1cm to the right of the text block centre:

\rule{\dimexpr.5\textwidth+1cm}{1pt}

\begin{center}
  \hspace{2cm}\includegraphics[height=3\baselineskip]{example-image-a}
\end{center}

\rule{\dimexpr.5\textwidth+1cm}{1pt}

\hfill\hspace{2cm}\includegraphics[height=3\baselineskip]{example-image-b}\hfill\mbox{}

\hrulefill

At the same location as some marker within a paragraph:

\noindent% Start a paragraph (if needed)
\zsaveposx{leftmargin}%
\hspace{\dimexpr\zposx{Xmarker}sp-\zposx{leftmargin}sp}%
\makebox[0pt]{\includegraphics[height=3\baselineskip]{example-image}}%

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse tempor sit amet 
ante sed X\makebox[0pt][l]{\hspace{1cm}\zsaveposx{Xmarker}} molestie. Proin scelerisque 
accumsan efficitur. Nulla sagittis nibh non ultrices gravida. Proin id diam et dolor 
iaculis lacinia id non felis.

\end{document}

答案2

在这三种情况下,我使用\tclap(顶部中心重叠)将上面的图像放在 的正后方!NOW!在第一种情况下,图像居中于 的右边缘!,而在第 2 和第 3 种情况下,2cm 图像向 的右侧移动 1cm !,导致图像左对齐于 的右边缘!

在第三种情况下,由于标记不在段落的第一行,因此添加了额外的技巧(\smash\vspace)来完成任务。

\documentclass{article}
\usepackage{stackengine,graphicx}
\def\IG{\includegraphics[width=2cm]{example-image}}
\begin{document}
Here is text. 
Here is text. 
Here is text.NOW!\tclap{\IG}
Here is text. Here is text. Here is text. Here is text. Here is text. 
Here is text. Here is text. Here is text. Here is text. Here is text. 
Here is text. Here is text. Here is text. Here is text. Here is text. 
Here is text. Here is text. Here is text. \smallskip

Here is text. 
Here is text. 
Here is text.NOW!\tclap{\hspace{2cm}\IG}
Here is text. Here is text. Here is text. Here is text. Here is text. 
Here is text. Here is text. Here is text. Here is text. Here is text. 
Here is text. Here is text. Here is text. Here is text. Here is text. 
Here is text. Here is text. Here is text. 
Here is text. \vspace{4\baselineskip}

Here is text. 
Here is text. 
Here is text.
Here is text. Here is text. Here is text. Here is text. Here is text. 
Here is text. Here is text. Here is text. Here is text. Here is text. 
Here is text. Here is text. Here is text. Here is text. Here is text. 
Here is text.%
NOW!\smash{\tclap[4\baselineskip]{\hspace{2cm}\IG}}
Here is text. Here is text. 
Here is text. 
\end{document}

在此处输入图片描述

相关内容