我正在使用 tikzpicture 在图像上写一些文字。
你们中是否有人知道如何定位文本节点,以便可能的可变长度句子(该文本节点)的最后一个字母始终与文档右边距保持相同的距离?
这是我当前的代码:
\documentclass[12pt]{article}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{titling}
\usepackage[margin=0.9in]{geometry}
\title{Article Y}
\author{Author X}
\date{\vspace{-2ex}{\small \today}}
\setlength{\droptitle}{-3.8em}
\pretitle{%
\begin{center}
\LARGE
\begin{tikzpicture}
\draw (0, 0) node[inner sep=0] {\includegraphics[width=\textwidth]{images/my-logo}};
\draw (5.5, -0.1) node {{\normalsize A possible variable sentence...}};
\end{tikzpicture}\\
[\bigskipamount]
}
\posttitle{\end{center}}
\begin{document}
\maketitle
\subsection*{Sec 1}
\subsection*{Sec 2}
\end{document}
如果无法使用 tikzpicture 来实现,欢迎使用其他方法。
答案1
这些节点距离页面右边距 2cm。您需要编译两次。如果您想要另一个参考点,请更改坐标线:
\documentclass[12pt]{article}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{titling}
\usepackage[margin=0.9in]{geometry}
\title{Article Y}
\author{Author X}
\date{\vspace{-2ex}{\small \today}}
\setlength{\droptitle}{-3.8em}
\pretitle{%
\begin{center}
\LARGE
\begin{tikzpicture}[remember picture]
\draw (0, 0) node[inner sep=0] {\includegraphics[width=\textwidth]{example-image}};
\coordinate (yline) at ([xshift=-2cm]current page.east);
\node[overlay,anchor=east] at (0,0 -| yline){{\normalsize A possible variable sentence...}};
\node[overlay,anchor=east] at (0,-0.5 -| yline){{\normalsize short}};
\node[overlay,anchor=east] at (0,-1 -| yline){{\normalsize a bit longer}};
\end{tikzpicture}\\
[\bigskipamount]
}
\posttitle{\end{center}}
\begin{document}
\maketitle
\subsection*{Sec 1}
\subsection*{Sec 2}
\end{document}
答案2
如果您只是想将文本放在图像上方,tikz
可能会有点小题大做。
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\setlength{\unitlength}{\textwidth}%
\begin{picture}(1,0.568382)%
\put(0,0){\includegraphics[width=\textwidth]{example-image}}%
\put(0.97,0.1){\makebox(0,0)[rb]{sentence}}%
\put(0.97,0.2){\makebox(0,0)[rb]{long sentence}}%
\end{picture}
\end{document}