长话短说,我通过center
环境在文本宽度的中间写了一句话,我想在某些单词的下面或上面放置一些文字来解释它们是如何组成的,例如
write + -ed
this is a sentence with written long time ago
我对支架并不是特别感兴趣,但如果必须选择的话,我希望它是这样的:
write + -ed
\____ ____/
V
this is a sentence with written long time ago
我显然知道underbrace
和overbrace
,以及_
和^
,但它们只在数学模式下工作,所以我想知道文本模式下是否存在可立即使用的解决方案。
答案1
如何使用overlay
tikzpicture
。您有tikzmark
和decorations
专门用于此的库。
例如:
\documentclass{article}
\usepackage {lipsum} % dummy text
\usepackage {tikz}
\usetikzlibrary{decorations.pathreplacing,tikzmark}
\tikzset{my brace/.style={decorate,decoration={brace,raise=-1mm,amplitude=2.5mm}}}
\begin{document}
\lipsum[1]
\begin{center}
\vspace*{0.5cm} % for the overlay picture
this is a sentence with \tikzmarknode{a}{written} long time ago
\end{center}
\begin{tikzpicture}[remember picture,overlay]
\node[yshift=0.7cm] (b) at (a) {\small\color{red}write $+$ -ed};
\draw[my brace] (b.south east) -- (b.south west);
\end{tikzpicture}
\lipsum[2]
\end{document}
编辑:要强制tikzpicture
与文本位于同一页面上,您可以将它们放在一个figure
环境中。这样:
\documentclass {article}
\usepackage {lipsum} % dummy text
\usepackage {tikz}
\usetikzlibrary{decorations.pathreplacing,tikzmark}
\tikzset{my brace/.style={decorate,decoration={brace,raise=-1mm,amplitude=2.5mm}}}
\begin{document}
\lipsum[1-4]
\lipsum[2]
\textcolor{blue}{Comment this line and see what happens.}
\begin{figure}[ht]\centering
\vspace*{0.5cm} % for the overlay picture
this is a sentence with \tikzmarknode{a}{written} long time ago
\begin{tikzpicture}[remember picture,overlay]
\node[yshift=0.7cm] (b) at (a) {\small\color{red}write $+$ -ed};
\draw[red,my brace] (b.south east) -- (b.south west);
\end{tikzpicture}
\end{figure}
\lipsum[5]
\end{document}
答案2
几周前我为一个朋友做了这件事。
\documentclass{article}
\usepackage{xcolor}
\newenvironment{annotated}{\par\linespread{1.5}\selectfont}{\par}
\newcommand{\xrulefill}{%
\leaders\hrule
height\dimexpr0.5ex+0.2pt\relax
depth-\dimexpr0.5ex-0.2pt\relax
\hfill
}
\NewDocumentCommand{\var}{smm}{%
\leavevmode\vbox{%
\offinterlineskip
\linespread{1}\selectfont
\ialign{%
##\hfil\cr
\textcolor{black!80}{%
\scriptsize\strut #3\IfBooleanT{#1}{\xrulefill}%
}\cr
\noalign{\vspace{-0.4ex}}
\strut#2\cr
}%
}%
}
\begin{document}
this is a sentence this is a sentence this is a sentence this is a sentence
this is a sentence this is \var{a}{one} sentence this is a
\var{sentence}{pqy} with text \var{written}{writ+-ed} long ago
this is a sentence this is a sentence this is a sentence
this is a sentence
\bigskip
\begin{annotated}
this is a sentence this is a sentence this is a sentence this is a sentence
this is a \var*{sentence}{xyz} this \var{}{missing} is a sentence this is a
\var{sentence}{pqy} with text \var{written}{writ+-ed} long ago
this is a sentence this is a sentence this is a sentence
this is a sentence
\end{annotated}
\end{document}
您可以\var
在任何地方使用,但正如您在第一个示例中看到的,行距会受到严重影响,因此我提供了annotated
增加行距的环境以适应此类文本变体(或注释)。
添加\var*
一条规则来涵盖所有内容,以便当变体影响多个单词时更好地指定它指的是什么。
你可能进行修改,使得变体不占用水平空间,但会牺牲清晰度。