我使用以下代码在段落中的文本周围绘制了一个多行框段落中句子周围的多行框 为了简单起见,我们将此多行框内文本称为突出显示的文本。
现在我想从中划一条线突出显示的文本到我组建的 TikZ 节点。以下是 MWE:
% The code must be run at least 2 times!
% The code from here until the begin{document} is taken from:
% https://tex.stackexchange.com/questions/116900/multi-line-box-around-a-sentence-in-a-paragraph
% with minor additions / modifications
\documentclass{article}
\usepackage{tikzpagenodes}
\usetikzlibrary{calc}
\usetikzlibrary{positioning}
\makeatletter
\tikzset{%
remember picture with id/.style={%
remember picture,
overlay,
save picture id=#1,
},
save picture id/.code={%
\edef\pgf@temp{#1}%
\immediate\write\pgfutil@auxout{%
\noexpand\savepointas{\pgf@temp}{\pgfpictureid}}%
},
if picture id/.code args={#1#2#3}{%
\@ifundefined{save@pt@#1}{%
\pgfkeysalso{#3}%
}{
\pgfkeysalso{#2}%
}
}
}
\def\savepointas#1#2{%
\expandafter\gdef\csname save@pt@#1\endcsname{#2}%
}
\def\tmk@labeldef#1,#2\@nil{%
\def\tmk@label{#1}%
\def\tmk@def{#2}%
}
\tikzdeclarecoordinatesystem{pic}{%
\pgfutil@in@,{#1}%
\ifpgfutil@in@%
\tmk@labeldef#1\@nil
\else
\tmk@labeldef#1,(0pt,0pt)\@nil
\fi
\@ifundefined{save@pt@\tmk@label}{%
\tikz@scan@one@point\pgfutil@firstofone\tmk@def
}{%
\pgfsys@getposition{\csname save@pt@\tmk@label\endcsname}\save@orig@pic%
\pgfsys@getposition{\pgfpictureid}\save@this@pic%
\pgf@process{\pgfpointorigin\save@this@pic}%
\pgf@xa=\pgf@x
\pgf@ya=\pgf@y
\pgf@process{\pgfpointorigin\save@orig@pic}%
\advance\pgf@x by -\pgf@xa
\advance\pgf@y by -\pgf@ya
}%
}
\newcommand\tikzmark[2][]{%
\tikz[remember picture with id=#2] #1;}
\makeatother
\newcommand\BoxedText[4][]{%
\begin{tikzpicture}[remember picture,overlay]
\draw[#1]
let \p1=(pic cs:#2), \p2=(pic cs:#3) in
([yshift=-0.8ex]\p1) --
([yshift=2ex]\p1) --
([xshift=3pt,yshift=2ex]\p1-|current page text area.east) --
([xshift=3pt,yshift=2ex]\p2-|current page text area.east) --
([yshift=2ex]\p2) --
([yshift=-0.8ex]\p2) --
([xshift=-3pt,yshift=-0.8ex]\p2-|current page text area.west) --
([xshift=-3pt,yshift=-0.8ex]\p1-|current page text area.west) --
cycle node (#4) {}
; % (#4) is added in order to name the node
\end{tikzpicture}%
}
\usepackage{blindtext}
\begin{document}
\BoxedText[]{start1}{end1}{MYPARAGRAPH}
% \blindtext[100] Nope, this doesn't work in this particular case.
Some text goes here. I have to add some text manually here. blindtext[100] doesn't work here. Sorry. Some text goes here. Some text goes here.Some text goes here.Some text goes here. Some text goes here.
\tikzmark{start1} Some text goes here. Some text goes here. Some text goes here. Some text goes here.Some text goes here.Some text goes here. Some text goes here. Some text goes here. Some text goes here. Some text Some text goes here \tikzmark{end1} Some text goes here. Some text goes here. Some text goes here. Some text goes here.Some text goes here. Some text goes here. Some text goes here. Some text goes here. Some text goes here. Some text Some text goes here
\begin{tikzpicture}[]
\node[rectangle,
below=0.5cm of MYPARAGRAPH,
draw=blue,]
(MYNOTE){\footnotesize Here is my note};
\draw[very thick,blue]
(MYPARAGRAPH) -| (MYNOTE);
\end{tikzpicture}
\end{document}
ed行\draw
似乎在段落结束的区域结束。我想将\draw
'ed 行延伸到突出显示文本的边框,如下所示:
怎么做?
答案1
一种方法是在文本周围绘制框时放置一个坐标。这里我将coordinate[midway](leftside)
这个坐标放置在框左侧的中间。
然后,我发现做相反的事情更容易,而不是尝试从节点绘制到这个地方:从框的左侧绘制到文本下方的某处,并将节点放在末尾。
显然,距离可以根据您的意愿进行调整。
% The code must be run at least 2 times!
% The code from here until the begin{document} is taken from:
% https://tex.stackexchange.com/questions/116900/multi-line-box-around-a-sentence-in-a-paragraph
% with minor additions / modifications
\documentclass{article}
\usepackage{tikzpagenodes}
\usetikzlibrary{calc}
\usetikzlibrary{positioning}
\makeatletter
\tikzset{%
remember picture with id/.style={%
remember picture,
overlay,
save picture id=#1,
},
save picture id/.code={%
\edef\pgf@temp{#1}%
\immediate\write\pgfutil@auxout{%
\noexpand\savepointas{\pgf@temp}{\pgfpictureid}}%
},
if picture id/.code args={#1#2#3}{%
\@ifundefined{save@pt@#1}{%
\pgfkeysalso{#3}%
}{
\pgfkeysalso{#2}%
}
}
}
\def\savepointas#1#2{%
\expandafter\gdef\csname save@pt@#1\endcsname{#2}%
}
\def\tmk@labeldef#1,#2\@nil{%
\def\tmk@label{#1}%
\def\tmk@def{#2}%
}
\tikzdeclarecoordinatesystem{pic}{%
\pgfutil@in@,{#1}%
\ifpgfutil@in@%
\tmk@labeldef#1\@nil
\else
\tmk@labeldef#1,(0pt,0pt)\@nil
\fi
\@ifundefined{save@pt@\tmk@label}{%
\tikz@scan@one@point\pgfutil@firstofone\tmk@def
}{%
\pgfsys@getposition{\csname save@pt@\tmk@label\endcsname}\save@orig@pic%
\pgfsys@getposition{\pgfpictureid}\save@this@pic%
\pgf@process{\pgfpointorigin\save@this@pic}%
\pgf@xa=\pgf@x
\pgf@ya=\pgf@y
\pgf@process{\pgfpointorigin\save@orig@pic}%
\advance\pgf@x by -\pgf@xa
\advance\pgf@y by -\pgf@ya
}%
}
\newcommand\tikzmark[2][]{%
\tikz[remember picture with id=#2] #1;}
\makeatother
\newcommand\BoxedText[4][]{%
\begin{tikzpicture}[remember picture,overlay]
\draw[#1]
let \p1=(pic cs:#2), \p2=(pic cs:#3) in
([yshift=-0.8ex]\p1) --
([yshift=2ex]\p1) --
([xshift=3pt,yshift=2ex]\p1-|current page text area.east) --
([xshift=3pt,yshift=2ex]\p2-|current page text area.east) --
([yshift=2ex]\p2) --
([yshift=-0.8ex]\p2) --
([xshift=-3pt,yshift=-0.8ex]\p2-|current page text area.west) --
([xshift=-3pt,yshift=-0.8ex]\p1-|current page text area.west) coordinate[midway](leftside) --
cycle node (#4) {}
; % (#4) is added in order to name the node
\end{tikzpicture}%
}
\usepackage{blindtext}
\begin{document}
\BoxedText[]{start1}{end1}{MYPARAGRAPH}
% \blindtext[100] Nope, this doesn't work in this particular case.
Some text goes here. I have to add some text manually here. \blindtext[1]
Some text goes here. Some text goes here.Some text goes here.Some text goes here. Some text goes here. \tikzmark{start1} Some text goes here. Some text goes here. Some text goes here. Some text goes here.Some text goes here.Some text goes here. Some text goes here. Some text goes here. Some text goes here. Some text Some text goes here \tikzmark{end1} Some text goes here. Some text goes here. Some text goes here. Some text goes here.Some text goes here. Some text goes here. Some text goes here. Some text goes here. Some text goes here. Some text Some text goes here
\begin{tikzpicture}[remember picture, overlay]
\draw[very thick,blue] (leftside) -|++ (-0.5,-2.2) -|++ (2,-.5) node [below,draw=blue,text=black] {\footnotesize Here is my note};
\end{tikzpicture}
\end{document}