太长;没读

太长;没读

太长;没读

看图,黄色的块其实是三个节点。

  • 如何提高锚边框
  • 如何将这样的节点放置于内联?
  • 或者,总的来说,有任何更好的机制可以做到这一点吗?

解释

我从这个八边形开始。黑色射线表示\anchorborder,它描绘了一个从 继承而来的矩形rectangle

\documentclass{article}
\usepackage{tikz}
\begin{document}

\makeatletter
\pgfset{
  left indent/.initial  =\parindent,
  right indent/.initial =\parindent,
  top indent/.initial   =\baselineskip,
  bottom indent/.initial=\baselineskip,
}
\pgfdeclareshape{html span}
{
  \inheritsavedanchors[from=rectangle]
  \inheritanchor[from=rectangle]{north}
  \inheritanchor[from=rectangle]{north west}
  \inheritanchor[from=rectangle]{north east}
  \inheritanchor[from=rectangle]{center}
  \inheritanchor[from=rectangle]{west}
  \inheritanchor[from=rectangle]{east}
  \inheritanchor[from=rectangle]{south}
  \inheritanchor[from=rectangle]{south west}
  \inheritanchor[from=rectangle]{south east}
  \inheritanchorborder[from=rectangle]
  \savedanchor\preindent{
    \pgfmathsetlength\pgf@x{\pgfkeysvalueof{/pgf/left indent}}
    \pgfmathsetlength\pgf@y{\pgfkeysvalueof{/pgf/top indent}}
  }
  \savedanchor\postindent{
    \pgfmathsetlength\pgf@x{\pgfkeysvalueof{/pgf/right indent}}
    \pgfmathsetlength\pgf@y{\pgfkeysvalueof{/pgf/bottom indent}}
  }
  \anchor{north west inner}{
    \southwest
    \pgf@xa=\pgf@x
    \northeast
    \pgf@ya=\pgf@y
    \preindent
    \advance\pgf@xa+\pgf@x \pgf@x=\pgf@xa
    \advance\pgf@ya-\pgf@y \pgf@y=\pgf@ya
  }
  \anchor{south east inner}{
    \southwest
    \pgf@ya=\pgf@y
    \northeast
    \pgf@xa=\pgf@x
    \postindent
    \advance\pgf@xa-\pgf@x \pgf@x=\pgf@xa
    \advance\pgf@ya+\pgf@y \pgf@y=\pgf@ya
  }
  \anchor{begin}{
    \southwest
    \pgf@xa=\pgf@x
    \northeast
    \pgf@ya=\pgf@y
    \preindent
    \advance\pgf@xa+  \pgf@x \pgf@x=\pgf@xa
    \advance\[email protected]\pgf@y \pgf@y=\pgf@ya
  }
  \anchor{end}{
    \southwest
    \pgf@ya=\pgf@y
    \northeast
    \pgf@xa=\pgf@x
    \postindent
    \advance\pgf@xa-  \pgf@x \pgf@x=\pgf@xa
    \advance\pgf@ya+.5\pgf@y \pgf@y=\pgf@ya
  }
  \backgroundpath{
    \southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
    \northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
    \preindent \pgf@xc=\pgf@x \pgf@yc=\pgf@y
    \pgfpathmoveto{\pgfqpoint{\pgf@xb        }{\pgf@yb        }}
    \pgfpathlineto{\pgfpoint {\pgf@xa+\pgf@xc}{\pgf@yb        }}
    \pgfpathlineto{\pgfpoint {\pgf@xa+\pgf@xc}{\pgf@yb-\pgf@yc}}
    \pgfpathlineto{\pgfpoint {\pgf@xa        }{\pgf@yb-\pgf@yc}}
    \postindent \pgf@xc=\pgf@x \pgf@yc=\pgf@y
    \pgfpathlineto{\pgfqpoint{\pgf@xa        }{\pgf@ya        }}
    \pgfpathlineto{\pgfpoint {\pgf@xb-\pgf@xc}{\pgf@ya        }}
    \pgfpathlineto{\pgfpoint {\pgf@xb-\pgf@xc}{\pgf@ya+\pgf@yc}}
    \pgfpathlineto{\pgfpoint {\pgf@xb        }{\pgf@ya+\pgf@yc}}
    \pgfpathclose
    \pgfsetarrowsstart{}
    \pgfsetarrowsend{}
 }
}

现在我们可以想象一些婴儿的用途。

\begin{tikzpicture}[remember picture]
    \node[fill=yellow,shape=html span,minimum width=5cm,minimum height=3\baselineskip,left indent=8em,right indent=6em](B){Bravo};
    \tiny\path(B.north west inner)node{$\times$\rlap{nw}}(B.south east inner)node{\llap{se}$\times$};
\end{tikzpicture}

\bigskip

\begin{tikzpicture}[remember picture]
    \node[fill=yellow,shape=html span,minimum width=5cm,minimum height=2\baselineskip,left indent=4.5cm,right indent=3.5cm](C){Charlie};
    \tiny\path(C.north west inner)node{$\times$\rlap{nw}}(C.south east inner)node{\llap{se}$\times$};
\end{tikzpicture}

\bigskip

\begin{tikzpicture}[remember picture,overlay]
    \draw[red,->](B.end)to[out=0,in=180](C.begin);
\end{tikzpicture}

为了正确放置它,我需要四个支持节点。

\newdimen\pgf@xd\newdimen\pgf@yd
\pgfset{
  inner sep=0pt,
  outer sep=0pt,
  html span over/.code args={(#1)(#2)(#3)(#4)}{
    \tikz@scan@one@point\pgfutil@firstofone(#1.north)
    \pgf@xa=\pgf@x \pgf@ya=\pgf@y
    \tikz@scan@one@point\pgfutil@firstofone(#2)
    \pgf@xb=\pgf@x \pgf@yb=\pgf@y
    \tikz@scan@one@point\pgfutil@firstofone(#3)
    \pgf@xc=\pgf@x \pgf@yc=\pgf@y
    \tikz@scan@one@point\pgfutil@firstofone(#4.south)
    \pgf@xd=\pgf@x \pgf@yd=\pgf@y
    \pgfset{
      left indent/.expanded  =\pgf@xa-\pgf@xb,
      right indent/.expanded =\pgf@xc-\pgf@xd,
      /tikz/shape=html span,
      /tikz/anchor=center,
      /tikz/text width/.expanded =\pgf@xc-\pgf@xb,
      /tikz/text height/.expanded=\pgf@ya-\pgf@yd,
      /tikz/text depth/.expanded =0
    }
    \edef\tikz@node@at{\noexpand\pgfpoint{.5\pgf@xb+.5\pgf@xc}{.5\pgf@ya+.5\pgf@yd}}%
  }
}
    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
    \tikz[overlay,remember picture]\node[anchor=base,red](D1){D1\strut};%
    \vadjust{\noindent\tikz[overlay,remember picture,red]\node(D2){D2};\hfill\tikz[overlay,remember picture,red]\node(D3){D3};}%
    Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.%
    \tikz[overlay,remember picture,red]\node[anchor=base](D4){D4\strut};
    Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
    \tikz[overlay,remember picture]\node[fill=yellow,opacity=.3,html span over=(D1)(D2)(D3)(D4)]{};

最后我可以将它们打包成两个命令:\nodehighlight(#1)\endnodehighlight(#1)

\def\nodehighlight(#1){%
    \tikz[overlay,remember picture]\node[anchor=base](#11){\strut};%
    \vadjust{\noindent\tikz[overlay,remember picture]\node(#12){};\hfill\tikz[overlay,remember picture]\node(#13){};}%
}
\def\endnodehighlight(#1){%
    \tikz[overlay,remember picture]\node[anchor=base](#14){\strut};%
    \tikz[overlay,remember picture]\node[fill=yellow,opacity=.3,html span over=(#11)(#12)(#13)(#14)](#1){};%
}
    Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. 
    \nodehighlight(E)%
    Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem.%
    \endnodehighlight(E)
    Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante.
    \nodehighlight(F)%
    Etiam sit amet orci eget eros faucibus tincidunt.%
    \endnodehighlight(F)
    Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc, quis gravida magna mi a libero. Fusce vulputate eleifend sapien. 
    \nodehighlight(G)%
    Vestibulum purus quam, scelerisque ut, mollis sed, nonummy id, metus. Nullam accumsan lorem in dui. Cras ultricies mi eu turpis hendrerit fringilla.%
    \endnodehighlight(G)
    Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; In ac dui quis mi consectetuer lacinia.
    \tikz[remember picture,overlay]\draw[red](E.end)to[out=0,in=180](F.begin)(F.end)to[out=0,in=180](G.begin);

问题)

  • 如何提高锚边框?我对最后一张图中的三种情况没有合理的想法。(即:保持在一条线上,分成两部分,跨越多条线。)
  • 如何正确放置这样的节点?在我的方法中,我假设每条线的总高度为\baselineskip,所以我没有更改top indentbottom indent
  • 小问题:
    • 填充背景,而不是前景。
    • 超出右边界以防跨越到下一行。
    • 在这种情况下,什么样的锚点有用?如何命名才能不言自明?
    • 跨越多页?
    • ...

相关内容