文本元标签

文本元标签

标签

我正在尝试在 LaTex 中重现此处所示的效果。我希望能够标记句子的各个部分,以帮助我的学生学习语法。

这可能吗?我不知道有任何包可以做到这一点。{我不确定要给它什么标签;如果 tikz 错了,请随时纠正。}

感谢您的帮助。

答案1

这是不是一个理想的答案,但既然我已经研究过了,我就把它贴出来。(已修改,提供两种替代方案)

我接受了大卫的建议,并重新修改了我的答案占位符文本周围的圆角框支持换行

版本 1:

有什么缺点:

1)由于我延续空格规则的方式(使用长度\afterspacelap),一个负面副作用是,超越规则会突出到续行的左边距。

2) 标签作为参数传递,位于\rlap文本标记右侧 2em 处。如果空间不够,可以像我对“LINEBREAKING”标签所做的那样向左重新排列,但如果空间不够,则没有补救办法。

3) 标签不会像 OP 的照片中那样破坏上线,而只是位于其上方。

好消息是它可以换行和分段。

\documentclass{article}
\usepackage{censor}
\usepackage{stackengine}
\usepackage{xcolor}
\usepackage{scalerel}
\newlength\rlwd
\rlwd=.8pt

\makeatletter
\setstackgap{L}{9pt}
\def\stacktype{L}
\def\useanchorwidth{T}
\censorruledepth=\Lstackgap

\periodrlap=0pt\relax
\afterperiodlap=0pt\relax
\lletterlap=0pt\relax
\rletterlap=0pt\relax
\afterspacelap=1.0ex\relax

\renewcommand\censorrule[1]{%
\protect\textcolor{cyan}{\rule[\censorruledepth]{#1}{\rlwd}}%
}

\renewcommand\@cenword[1]{%
  \setbox0=\hbox{#1}%
  \stackon[0pt]{#1}{\censorrule{\wd0}}%
}

\def\censordot{\textcolor{cyan}{\rlap{\@cenword{\phantom{.}}}}.}

\def\endleft{\rule[\Lstackgap-3pt+.7\rlwd]{\rlwd}{3pt}}
\let\endright\endleft

\newcommand\marktext[2][]{%
\trlap[11pt]{\sffamily\bfseries\scriptsize\textcolor{cyan}{\hspace{2em}{\uppercase{#1}}}}%
\textcolor{cyan}{\llap{\smash{\endleft}}}%
\xblackout{#2}%
\textcolor{cyan}{\rlap{\smash{\endright}}}%
}

\makeatother
\parindent 0in
\parskip 1em
\begin{document}

This shows linebreaking capability: aaa aaa aaa aaa aaa aaa aaa
\marktext[\kern-13pt linebreaking]{bbb bbb bbb bbb. bbb bbb bbb bbb bbb bbb}
ccc ccc ccc ccc ccc ccc

Can this \marktext[phrase]{procedure go across paragraphs boundaries?

Why yes} it can.

But gaps can arise if glue is stretched too far.

\afterspacelap=1.7ex\relax
\marktext[sentences]{%
This tests marking a multiline block of text.  This tests marking a multiline block of text.
This tests marking a multiline block of text.  This tests marking a multiline block of text.
This tests marking a multiline block of text.}

\end{document}

在此处输入图片描述


版本 2:

此修订版本的优点是,它平等地延伸到换行的左右边距,但这是有代价的。代价是蓝色上线的前端和后端同样延伸了这一量,

\documentclass{article}
\usepackage{censor}
\usepackage{stackengine}
\usepackage{xcolor}
\usepackage{scalerel}
\newlength\rlwd
\rlwd=.8pt

\makeatletter
\setstackgap{L}{9pt}
\def\stacktype{L}
\def\useanchorwidth{T}
\censorruledepth=\Lstackgap

\periodrlap=.5ex\relax
\afterperiodlap=.5ex\relax
\lletterlap=.5ex\relax
\rletterlap=.5ex\relax
\afterspacelap=.5ex\relax

\renewcommand\censorrule[1]{%
\protect\textcolor{cyan}{\rule[\censorruledepth]{#1}{\rlwd}}%
}

\renewcommand\@cenword[1]{%
  \setbox0=\hbox{#1}%
  \stackon[0pt]{#1}{\censorrule{\wd0}}%
}

\def\censordot{\textcolor{cyan}{%
  \rlap{\@cenword{\phantom{.\hspace{\periodrlap}}}}}.}

\def\endleft{\rule[\Lstackgap-3pt+.7\rlwd]{\rlwd}{3pt}}
\let\endright\endleft

\newcommand\marktext[2][]{%
\trlap[11pt]{\sffamily\bfseries\scriptsize\textcolor{cyan}{\hspace{2em}{\uppercase{#1}}}}%
\textcolor{cyan}{\llap{\smash{\endleft}\hspace{\lletterlap}}}%
\xblackout{#2}%
\textcolor{cyan}{\rlap{\hspace{\rletterlap}\smash{\endright}}}%
}

\makeatother
\parindent 0in
\parskip 1em
\begin{document}

This shows linebreaking capability: aaa aaa aaa aaa aaa aaa aaa
\marktext[\kern-13pt linebreaking]{bbb bbb bbb bbb. bbb bbb bbb bbb bbb bbb}
ccc ccc ccc ccc ccc ccc

Can this \marktext[phrase]{procedure go across paragraphs boundaries?

Why yes} it can.

But gaps can arise if glue is stretched too far.

\periodrlap=.8ex\relax
\afterperiodlap=.9ex\relax
\lletterlap=.8ex\relax
\rletterlap=.8ex\relax
\afterspacelap=.8ex\relax
\marktext[sentences]{%
This tests marking a multiline block of text.  This tests marking a multiline block of text.
This tests marking a multiline block of text.  This tests marking a multiline block of text.
This tests marking a multiline block of text.}

\end{document}

在此处输入图片描述

相关内容