我正在与不在现场的某人共同编辑一份手稿。为了更好地标明我们每个人所做的更改并减少电子邮件数量,我想在我所做的更改旁边的空白处添加一个竖线,如下所示:
text not change
\verticalbar{
text changed
}
text not changed
我知道所做的更改可能会在一行的中间开始/结束。在这种情况下,我们希望竖线覆盖部分行。出于各种原因,\underline 或 \textcolor 对我们来说不起作用。
感谢您的帮助和建议!
答案1
经过仔细考虑,我得出结论,使用tcolorbox
或其他基于框的方法可能不是最佳选择,因为您只能在完整段落旁边画一条线。但是,从您的示例中,我理解该线还应该能够在更改部分开始或结束的行上开始或结束,即在段落内的某个位置。
因此,我建议一个基于 的解决方案tikzmarks
。这些标记可以准确地放置在更改开始和结束的位置,然后绘制一条红线,覆盖放置这两个标记的两条线之间的所有内容。
但是,该解决方案的一个缺点是它不能跨越多页。
此示例允许您为线条选择自定义颜色:
\documentclass[]{article}
\usepackage{lipsum} % only used to generate filler text
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\newcounter{changebar}
\newcommand{\changebarcolor}{red}
\newcommand{\changestart}[1][red]{%
\renewcommand{\changebarcolor}{#1}%
\stepcounter{changebar}%
\tikzmarknode{chbar-\thechangebar-start}{\strut}%
}
\newcommand{\changeend}{%
\tikzmarknode{chbar-\thechangebar-end}{\strut}%
\begin{tikzpicture}[remember picture, overlay]
\draw[very thick, \changebarcolor] ([xshift={\oddsidemargin+1in-10pt}]current page.west |- chbar-\thechangebar-start.north) -- ([xshift={\oddsidemargin+1in-10pt}]current page.west |- chbar-\thechangebar-end.south);
\end{tikzpicture}%
}
\begin{document}
\lipsum[1]\changestart\lipsum[1]\changeend\lipsum[1]
In this sentence, only one \changestart[blue]word\changeend{} was changed.
\end{document}
您需要编译该文档至少两次,以获得正确的线条定位。
请注意,由于 TeX 的空间吞噬特性,如果后面有空格,则需要在宏后添加一组空花括号,或者告诉 TeX 不应忽略后面的空格。
通过一些工作,可以得到一个即使在分页符下也能正常工作的解决方案(最初受到启发这和这方法):
\documentclass{article}
\usepackage{lipsum} % only used for filler text
\usepackage{tikz}
\usepackage{tikzpagenodes}
\usetikzlibrary{tikzmark}
\makeatletter
\newcommand{\getchbarstartendpages}[1]{%
% #1 = change bar id,
\edef\chbarstartmarkid{\csname save@pt@chbar-#1-start\endcsname}%
\edef\chbarstartpage{\csname save@pg@\chbarstartmarkid\endcsname}%
\edef\chbarendmarkid{\csname save@pt@chbar-#1-end\endcsname}%
\edef\chbarendpage{\csname save@pg@\chbarendmarkid\endcsname}%
}
\makeatother
\newcommand{\chbarifsplit}[3]{%
% #1 = change bar id,
% #2 = not split, #3 = split
\getchbarstartendpages{#1}%
\ifnum\chbarstartpage=\chbarendpage\relax%
{#3}%
\else%
{#2}%
\fi%
}
\newcounter{changebar}
\newcommand{\changebarcolor}{red}
\newcommand{\changestart}[1][red]{%
\renewcommand{\changebarcolor}{#1}%
\stepcounter{changebar}%
\tikzmarknode{chbar-\thechangebar-start}{\strut}%
\chbarifsplit{\thechangebar}{%
\begin{tikzpicture}[remember picture, overlay]
\draw[very thick, \changebarcolor] ([xshift={\oddsidemargin+1in-10pt}]current page.west |- chbar-\thechangebar-start.north) -- ([xshift={\oddsidemargin+1in-10pt}]current page.west |- current page text area.south);
\end{tikzpicture}%
}{}%
}
\newcommand{\changeend}{%
\tikzmarknode{chbar-\thechangebar-end}{\strut}%
\chbarifsplit{\thechangebar}{%
\begin{tikzpicture}[remember picture, overlay]
\draw[very thick, \changebarcolor] ([xshift={\oddsidemargin+1in-10pt}]current page.west |- current page text area.north) -- ([xshift={\oddsidemargin+1in-10pt}]current page.west |- chbar-\thechangebar-end.south);
\end{tikzpicture}%
}{%
\begin{tikzpicture}[remember picture, overlay]
\draw[very thick, \changebarcolor] ([xshift={\oddsidemargin+1in-10pt}]current page.west |- chbar-\thechangebar-start.north) -- ([xshift={\oddsidemargin+1in-10pt}]current page.west |- chbar-\thechangebar-end.south);
\end{tikzpicture}%
}%
}
\AddToHook{shipout/background}{
% for older LaTeX installations use instead:
% \usepackage{everypage}
% \AddEverypageHook{
\getchbarstartendpages{\thechangebar}%
\ifnum\chbarstartpage<\thepage\relax%
\ifnum\chbarendpage>\thepage\relax%
\begin{tikzpicture}[remember picture, overlay]
\draw[very thick, \changebarcolor] ([xshift={\oddsidemargin+1in-10pt}]current page.west |- current page text area.north) -- ([xshift={\oddsidemargin+1in-10pt}]current page.west |- current page text area.south);
\end{tikzpicture}%
\fi
\fi
}
\begin{document}
\lipsum[1] \changestart\lipsum[1]\changeend{} \lipsum[1]
In this sentence, only one \changestart[blue]word\changeend{} was changed.
Hello my friend. What took you so long? How have you been? \changestart[orange]\lipsum[1]\changeend{} \lipsum[1]
\changestart[cyan]\lipsum[1-10]\changeend{} \lipsum[1]
\end{document}
输出: