![将图像放置在页面角落,下方有 tikz 和文本](https://linux22.com/image/438970/%E5%B0%86%E5%9B%BE%E5%83%8F%E6%94%BE%E7%BD%AE%E5%9C%A8%E9%A1%B5%E9%9D%A2%E8%A7%92%E8%90%BD%EF%BC%8C%E4%B8%8B%E6%96%B9%E6%9C%89%20tikz%20%E5%92%8C%E6%96%87%E6%9C%AC.png)
这里是 LaTeX 新手。
我正在尝试将图像(无固定高度)放置在页面的右上角。为了实现这一点,我使用 tikz 和叠加层,并记住其他地方建议的图片选项。然而,这显然意味着我想要包含的任何文本都会叠加在图片之上,而我希望文本出现在下方,就像它是一个普通的图形一样。
以下是一个最小的工作示例
\RequirePackage{tikz}
\RequirePackage{geometry}
%Used to make calculations with coordinates for positioning
\RequirePackage{calc}
%Width of border on the left with section title
\newlength{\titleborderwidth}
%Set border width
\setlength{\titleborderwidth}{0.16\paperwidth}
%Set page geometry
\geometry{inner=\titleborderwidth}
\begin{document}
\begin{tikzpicture}[remember picture, overlay]
\node[anchor=north east] at (current page.north east){
\includegraphics[width=\paperwidth-\titleborderwidth]{example-image-a}
};
\end{tikzpicture}
\\
I would like this text to appear below the picture
\end{document}
得出的结果为:
此外:
我需要边框宽度的原因是因为我计划的文档有一个边框,标题垂直位于左侧。
目前,使用此 MWE,图像似乎无法完美地适合右上角,但似乎有一些白色边缘,我不确定为什么。
我无法弄清楚是否有办法获取图片的大小(该大小不是预设的并且可能会发生变化)以将其用作 \vspace 的参数。
我更愿意使用 tikz,因为在最终文档中,我正在使用带有阴影库的其他 tikz 对象,并且我希望能够对此图像使用相同的库。
我已经花了很多时间尝试自己解决这个问题,但没有找到任何不粗俗或俗气的解决方案。如果你能传授我一些 LaTeX 知识,我会非常高兴。谢谢!
答案1
看起来您想在图片之后继续发短信。因此图片是文本的一部分,而不是浮动对象(在 CSS 意义上)。因此这里唯一不寻常的是图片应该触及顶部边距。只要您确切知道该边距中的内容,这很容易。
\documentclass{article}
\usepackage{geometry}
\newlength{\titleborderwidth}
\setlength{\titleborderwidth}{0.16\paperwidth}
\geometry{inner=\titleborderwidth}
\usepackage{layout}
\usepackage{tikz}
\begin{document}
\xdef\exacttopmargin{\the\dimexpr1em+\headsep+\headheight+\topmargin+1in\relax}%
\vspace*{-\exacttopmargin}%
\xdef\picturewidth{\the\dimexpr\paperwidth-\titleborderwidth\relax}%
\noindent\includegraphics[width=\picturewidth]{example-image-a}
I would like this text to appear below the picture.
And you can.
As you see, the only thing you need to do
is to ``unskip'' the the correct amount of top margin
so that the picture appears right on the top border.
To obtain the correct amount of top margin,
use package layout and use the command \texttt{\string\layout}.
This command will draw the page layout and tell you the commands
that represents the distances between certain layout-objects.
Once you see the layout, you know what dimensions to add together.
And then you add the negative of that dimensions.
And you are done.
You may also want to checkout the package showframe,
which shows the layout on every page.
\layout
\end{document}
答案2
\documentclass{article}
\usepackage{graphicx}
\RequirePackage{tikz}
\RequirePackage{geometry}
%Used to make calculations with coordinates for positioning
\RequirePackage{calc}
%Width of border on the left with section title
\newlength{\titleborderwidth}
%Set border width
\setlength{\titleborderwidth}{0.16\paperwidth}
%Set page geometry
\geometry{inner=\titleborderwidth}
\begin{document}
\begin{tikzpicture}[remember picture, overlay]
\node[anchor=north east, align=left, inner sep=0] at (current page.north east){
\includegraphics[width=\paperwidth-\titleborderwidth]{example-image-a} \\
I would like this text to appear below the picture
};
\end{tikzpicture}
\end{document}