答案1
看起来您想在文本行的正下方绘制线条。您可以使用以下方法精确地绘制一条穿过放置宏的位置的线条(水平地位于文本的基线处):
例如,绿色虚线将单词“vertical”精确地划分在 t 和 i 之间。如果需要,甚至可以对线条进行样式设置。您需要编译两次才能获得正确的位置。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\newcounter{linecount}
\newcommand{\horizontalline}[1][]{%
\stepcounter{linecount}%
\tikzmark{hlineanchor\thelinecount}%
\begin{tikzpicture}[remember picture, overlay]
\draw[#1] ({current page.west} |- {pic cs:hlineanchor\thelinecount}) -- ({current page.east} |- {pic cs:hlineanchor\thelinecount});
\end{tikzpicture}%
}
\newcommand{\verticalline}[1][]{%
\stepcounter{linecount}%
\tikzmark{vlineanchor\thelinecount}%
\begin{tikzpicture}[remember picture, overlay]
\draw[#1] ({current page.north} -| {pic cs:hlineanchor\thelinecount}) -- ({current page.south} -| {pic cs:hlineanchor\thelinecount});
\end{tikzpicture}%
}
\usepackage{lipsum}
\begin{document}
Hello horizontal line! \horizontalline[blue]
\lipsum[1]
Hello the other horizontal line! \horizontalline[red]
\lipsum[1]
And then, there is a vert\verticalline[green!50!black, thick, dashed]ical line that divides the word `vertical' exactly in the middle!
\end{document}
答案2
使用tikz
(确保运行两次):
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[remember picture, overlay]
\draw[line width=1.5pt, blue]
([yshift=-2in]current page.north west) -- ([yshift=-2in]current page.north east);
\draw[line width=1.5pt, green]
([xshift=-6in]current page.north east) -- ([xshift=-6in]current page.south east);
\end{tikzpicture}
\end{document}