![将具有可变长度句子的节点始终放置在与右边距相同的距离处](https://linux22.com/image/362982/%E5%B0%86%E5%85%B7%E6%9C%89%E5%8F%AF%E5%8F%98%E9%95%BF%E5%BA%A6%E5%8F%A5%E5%AD%90%E7%9A%84%E8%8A%82%E7%82%B9%E5%A7%8B%E7%BB%88%E6%94%BE%E7%BD%AE%E5%9C%A8%E4%B8%8E%E5%8F%B3%E8%BE%B9%E8%B7%9D%E7%9B%B8%E5%90%8C%E7%9A%84%E8%B7%9D%E7%A6%BB%E5%A4%84.png)
我正在使用 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}