Word 允许所有类型的字体格式:
上述示例结合了删除线/删除线(像这样)和下划线。我希望能够做同样的事情,但ulem
也不soul
以方便的方式实现这一点。
ulem
:\documentclass{article} \usepackage[a6paper,showframe]{geometry}% Just for this example \usepackage{ulem} \begin{document} Lorem ipsum dolor sit amet, \sout{consectetur adipiscing elit. Praesent} in nisi magna. Mauris \sout{auctor gravida} fermentum. Proin enim \uline{massa, \sout{\textbf{lobortis in} ligula} vel, convallis} fermentum nulla. \uline{Nam in mattis nulla}. Vestibulum vel \uline{auctor orci. Praesent \textit{\textbf{ornare, eros} ac} euismod} congue, turpis est facilisis nisi, a sollicitudin massa lectus imperdiet tellus. Duis at tempor velit. \sout{Nulla \uline{gravida}, dolor in cursus}. \end{document}
soul
:这
soul
文档明确指出“嵌套soul
命令不起作用”:因此,以下示例无法顺利编译:
\documentclass{article} \usepackage[a6paper,showframe]{geometry}% Just for this example \usepackage{soul} \begin{document} Lorem ipsum dolor sit amet, \st{consectetur adipiscing elit. Praesent} in nisi magna. Mauris \st{auctor gravida} fermentum. Proin enim \ul{massa, \st{\textbf{lobortis in} ligula} vel, convallis} fermentum nulla. \ul{Nam in mattis nulla}. Vestibulum vel \ul{auctor orci. Praesent \textit{\textbf{ornare, eros} ac} euismod} congue, turpis est facilisis nisi, a sollicitudin massa lectus imperdiet tellus. Duis at tempor velit. \st{Nulla \ul{gravida}, dolor in cursus}. \end{document}
理想情况下,我希望能够交替使用这些字体“效果”宏:删除线内下划线,或删除线内下划线,而不影响字体的使用(如斜体或者大胆的)。以下是 Word 的输出:
(另请参阅后续问题:下划线 + 删除线使用 soul)
答案1
以下是 Martin 的回答的改编版LaTeX 中的酷炫文本突出显示\tikzst
其中我根据马丁的定义\tikzul
。
这显示了
- 删除并划线
- 删除并突出显示
笔记:
通常,
\tikzmark
解决方案需要运行两次。由于嵌套使用\tikzmark
,因此需要三运行。(感谢@Werner指出这一点)。tikzmark
由于嵌套的的位置取决于父级 的位置,因此需要额外的运行\tikzmark
。因此,第一次运行稳定了“外部” 的位置\tikzmark
,第二次运行稳定了“内部” 的位置\tikzmark
,第三次运行进行实际绘制。来自
\tikzmark
在正文旁边添加大括号。
代码:
\documentclass[twoside,11pt]{book}
\usepackage{zref-abspage}
\usepackage{zref-user}
\usepackage{tikz}
\usepackage{atbegshi}
\usetikzlibrary{calc,decorations.pathmorphing}
\makeatletter
\newcommand{\currentsidemargin}{%
\ifodd\zref@extract{textarea-\thetextarea}{abspage}%
\oddsidemargin%
\else%
\evensidemargin%
\fi%
}
\newcounter{textarea}
\newcommand{\settextarea}{%
\stepcounter{textarea}%
\zlabel{textarea-\thetextarea}%
\begin{tikzpicture}[overlay,remember picture]
% Helper nodes
\path (current page.north west) ++(\hoffset, -\voffset)
node[anchor=north west, shape=rectangle, inner sep=0, minimum width=\paperwidth, minimum height=\paperheight]
(pagearea) {};
\path (pagearea.north west) ++(1in+\currentsidemargin,-1in-\topmargin-\headheight-\headsep)
node[anchor=north west, shape=rectangle, inner sep=0, minimum width=\textwidth, minimum height=\textheight]
(textarea) {};
\end{tikzpicture}%
}
\usepackage{lipsum}
\newcommand\xlipsum[1][]{{\let\par\relax\lipsum*[#1]}}
\tikzset{tikzul/.style={yshift=-.75\dp\strutbox}}
\newcounter{tikzul}%
\newcommand\tikzul[1][]{%
\begingroup
\global\tikzullinewidth\linewidth
\def\tikzulsetting{[#1]}%
\stepcounter{tikzul}%
\settextarea
\zlabel{tikzul-begin-\thetikzul}%
\tikz[overlay,remember picture,tikzul] \coordinate (tikzul-\thetikzul) at (0,0);% Modified \tikzmark macro
\ifnum\zref@extract{tikzul-begin-\thetikzul}{abspage}=\zref@extract{tikzul-end-\thetikzul}{abspage}
\else
\AtBeginShipoutNext{\tikzul@endpage{#1}}%
\fi
\bgroup
\def\par{\ifhmode\unskip\fi\egroup\par\@ifnextchar\noindent{\noindent\tikzul[#1]}{\tikzul[#1]\bgroup}}%
\aftergroup\endtikzul
\let\@let@token=%
}
\newlength\tikzullinewidth
\def\tikzul@endpage#1{%
\setbox\AtBeginShipoutBox\hbox{%
\box\AtBeginShipoutBox
\hbox{%
\begin{tikzpicture}[overlay,remember picture,tikzul]
\draw[#1]
let \p1 = (tikzul-\thetikzul), \p2 = ([xshift=\tikzullinewidth+\@totalleftmargin]textarea.south west) in
\ifdim\dimexpr\y1-\y2<.5\baselineskip
(\x1,\y1) -- (\x2,\y1)
\else
let \p3 = ([xshift=\@totalleftmargin]textarea.west) in
(\x1,\y1) -- +(\tikzullinewidth-\x1+\x3,0)
% (\x3,\y2) -- (\x2,\y2)
(\x3,\y1)
\myloop{\y1-\y2+.5\baselineskip}{%
++(0,-\baselineskip) -- +(\tikzullinewidth,0)
}%
\fi
;
\end{tikzpicture}%
}}%
}%
\def\endtikzul{%
\zlabel{tikzul-end-\thetikzul}%
\ifnum\zref@extract{tikzul-begin-\thetikzul}{abspage}=\zref@extract{tikzul-end-\thetikzul}{abspage}
\begin{tikzpicture}[overlay,remember picture,tikzul]
\expandafter\draw\tikzulsetting
let \p1 = (tikzul-\thetikzul), \p2 = (0,0) in
\ifdim\y1=\y2
(\x1,\y1) -- (\x2,\y2)
\else
let \p3 = ([xshift=\@totalleftmargin]textarea.west), \p4 = ([xshift=-\rightmargin]textarea.east) in
(\x1,\y1) -- +(\tikzullinewidth-\x1+\x3,0)
(\x3,\y2) -- (\x2,\y2)
(\x3,\y1)
\myloop{\y1-\y2}{%
++(0,-\baselineskip) -- +(\tikzullinewidth,0)
}%
\fi
;
\end{tikzpicture}%
\else
\settextarea
\begin{tikzpicture}[overlay,remember picture,tikzul]
\expandafter\draw\tikzulsetting
let \p1 = ([xshift=\@totalleftmargin,yshift=-.5\baselineskip]textarea.north west), \p2 = (0,0) in
\ifdim\dimexpr\y1-\y2<.5\baselineskip
(\x1,\y2) -- (\x2,\y2)
\else
let \p3 = ([xshift=\@totalleftmargin]textarea.west), \p4 = ([xshift=-\rightmargin]textarea.east) in
(\x3,\y2) -- (\x2,\y2)
(\x3,\y2)
\myloop{\y1-\y2}{%
++(0,+\baselineskip) -- +(\tikzullinewidth,0)
}
\fi
;
\end{tikzpicture}%
\fi
\endgroup
}
% -------------------------------------------------------------- Additions by Peter Grill
\tikzset{tikzst/.style={yshift=0.5\dp\strutbox}}
\newcounter{tikzst}%
\newcommand\tikzst[1][]{%
\begingroup
\global\tikzstlinewidth\linewidth
\def\tikzstsetting{[#1]}%
\stepcounter{tikzst}%
\settextarea
\zlabel{tikzst-begin-\thetikzst}%
\tikz[overlay,remember picture,tikzst] \coordinate (tikzst-\thetikzst) at (0,0);% Modified \tikzmark macro
\ifnum\zref@extract{tikzst-begin-\thetikzst}{abspage}=\zref@extract{tikzst-end-\thetikzst}{abspage}
\else
\AtBeginShipoutNext{\tikzst@endpage{#1}}%
\fi
\bgroup
\def\par{\ifhmode\unskip\fi\egroup\par\@ifnextchar\noindent{\noindent\tikzst[#1]}{\tikzst[#1]\bgroup}}%
\aftergroup\endtikzst
\let\@let@token=%
}
\newlength\tikzstlinewidth
\def\tikzst@endpage#1{%
\setbox\AtBeginShipoutBox\hbox{%
\box\AtBeginShipoutBox
\hbox{%
\begin{tikzpicture}[overlay,remember picture,tikzst]
\draw[#1]
let \p1 = (tikzst-\thetikzst), \p2 = ([xshift=\tikzstlinewidth+\@totalleftmargin]textarea.south west) in
\ifdim\dimexpr\y1-\y2<.5\baselineskip
(\x1,\y1) -- (\x2,\y1)
\else
let \p3 = ([xshift=\@totalleftmargin]textarea.west) in
(\x1,\y1) -- +(\tikzstlinewidth-\x1+\x3,0)
% (\x3,\y2) -- (\x2,\y2)
(\x3,\y1)
\myloop{\y1-\y2+.5\baselineskip}{%
++(0,-\baselineskip) -- +(\tikzstlinewidth,0)
}%
\fi
;
\end{tikzpicture}%
}}%
}%
\def\endtikzst{%
\zlabel{tikzst-end-\thetikzst}%
\ifnum\zref@extract{tikzst-begin-\thetikzst}{abspage}=\zref@extract{tikzst-end-\thetikzst}{abspage}
\begin{tikzpicture}[overlay,remember picture,tikzst]
\expandafter\draw\tikzstsetting
let \p1 = (tikzst-\thetikzst), \p2 = (0,0) in
\ifdim\y1=\y2
(\x1,\y1) -- (\x2,\y2)
\else
let \p3 = ([xshift=\@totalleftmargin]textarea.west), \p4 = ([xshift=-\rightmargin]textarea.east) in
(\x1,\y1) -- +(\tikzstlinewidth-\x1+\x3,0)
(\x3,\y2) -- (\x2,\y2)
(\x3,\y1)
\myloop{\y1-\y2}{%
++(0,-\baselineskip) -- +(\tikzstlinewidth,0)
}%
\fi
;
\end{tikzpicture}%
\else
\settextarea
\begin{tikzpicture}[overlay,remember picture,tikzst]
\expandafter\draw\tikzstsetting
let \p1 = ([xshift=\@totalleftmargin,yshift=-.5\baselineskip]textarea.north west), \p2 = (0,0) in
\ifdim\dimexpr\y1-\y2<.5\baselineskip
(\x1,\y2) -- (\x2,\y2)
\else
let \p3 = ([xshift=\@totalleftmargin]textarea.west), \p4 = ([xshift=-\rightmargin]textarea.east) in
(\x3,\y2) -- (\x2,\y2)
(\x3,\y2)
\myloop{\y1-\y2}{%
++(0,+\baselineskip) -- +(\tikzstlinewidth,0)
}
\fi
;
\end{tikzpicture}%
\fi
\endgroup
}
% --------------------------------------------------------------
\def\myloop#1#2#3{%
#3%
\ifdim\dimexpr#1>1.1\baselineskip
#2%
\expandafter\myloop\expandafter{\the\dimexpr#1-\baselineskip\relax}{#2}%
\fi
}
\makeatother
\begin{document}
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text \tikzul[red]{text text text text \tikzst[black, ultra thick]{text text text text text
text text text text text text text text} text text text
text text text text} text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
{\tikzset{tikzul/.style={yshift=1ex}}
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit,
vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida
mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna.
Donec vehicula augue eu neque. Pellentesque habitant morbi tristique senectus
et netus et malesuada fames ac turpis egestas. Mauris ut leo. Cras viverra
metus rhoncus sem. Nulla et lectus vestibulum urna fringilla ultrices. Phasellus
eu tellus sit amet tortor gravida placerat. Integer sapien est, iaculis in, pretium
quis, viverra ac, nunc. Praesent eget sem vel leo ultrices bibendum. \tikzul[line width=1.5\ht\strutbox,semitransparent,yellow]{Aenean
faucibus. Morbi dolor nulla, \tikzst[black, ultra thick]{malesuada eu, pulvinar at, mollis ac, nulla. Curabitur auctor semper nulla. Donec varius orci eget risus. Duis nibh mi, congue
eu, accumsan eleifend, sagittis quis}, diam. Duis eget orci sit amet orci dignissim
rutrum.}
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
test
}
\begin{quote}
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text \tikzul[red]{text text text \tikzst[black, ultra thick]{text text text text text text
text text text text text text text text text text text
text text text text text text text} text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text} text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
\end{quote}
{\tikzset{tikzul/.style={yshift=.5ex}}
\begin{quote}
text text text text text text text text text text text
text text text text text text text text text text text
\begin{quote}
text text text text text text text text text text text
text text \tikzul[green]{text text \tikzst[black, ultra thick]{text text text text text text text
text text text text text text text text text text text
text text text text
text text text text text text text}
text text text text text text text text text text text
text text text text text text text text text text text
text text text text} text text text text text text text
\end{quote}
text text text text text text text text text text text
text text text text text text text text text text text
\end{quote}
\large
new text text text text text text text text text text text
text text \tikzul[red]{first text text text text \tikzst[black, ultra thick]{text text text text
teXt teXt teXt teXt teXt teXt teXt teXt teXt teXt teXt
teXt teXt teXt} teXt teXt teXt teXt teXt teXt teXt teXt
teXt teXt teXt last} teXt teXt teXt teXt teXt teXt teXt
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text \tikzul[red]{text text text text text text text text text
text text\par\noindent text text text text text text text text text
text text text text} text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
}
\begin{itemize}
\item \tikzul{test test test} test
\item test \tikzul{test test test} test
\item aa \tikzul{test test test} test
\item b \tikzul{test test
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
test} test
\end{itemize}
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text \tikzul[red]{text text text text text text text text text
text text
text text text text text text text text text
text text text text} text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text \tikzul[red]{text text text text text text text text text
text text
\noindent text text text text text text text text text
\par text text text text} text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
\end{document}
答案2
有几个选项——以下所有选项都支持换行:
lua-ul
:https://tex.stackexchange.com/a/533377/250119(特定于突出显示+下划线,最简单的解决方案,默认有效)- 自定义答案使用
tikz
:https://tex.stackexchange.com/a/176118/250119(允许任意嵌套但如果嵌套则需要≥3次编译) soulpos
:请参阅我的回答https://tex.stackexchange.com/a/685471/250119(特定于突出显示+删除线)——需要了解 TeX 编程来定义命令,这需要 2 次编译。soul
:https://tex.stackexchange.com/a/178701/250119(特定于删除线+下划线)——这个包本身使用\leaders
,所以答案通过重复 0.1pt 宽度的框来工作,从而产生较重的 PDF。
这些解决方案不支持换行:
censor
:https://tex.stackexchange.com/a/178691/250119(删除线+下划线专用)soul
使用保存箱等:https://tex.stackexchange.com/a/418106/250119(特定于高亮+下划线)
为了完成,下面是一个使用的解决方案ulem
(改编自我的答案定义\dwave
)——ulem
没有“统一水平”的限制,但是不支持连字符任何一个:
%! TEX program = lualatex
\documentclass{article}
\usepackage{ulem}
\makeatletter
\protected\def\ulinesout{%
\leavevmode \bgroup
\UL@setULdepth
\markoverwith {%
\rlap{\rule[.55ex]{2pt}{0.4pt}}%
\rule[-\ULdepth]{2pt}{0.4pt}% \rule[-.673ex]{2pt}{0.4pt}
}%
\ULon
}
\makeatother
\begin{document}
\uline{a}\ulinesout{b}\sout{c}
\uline{Producing a colored underline or strike-through is }\ulinesout{not supported by
regular uline}\sout{ or sout, but it is quite easy to colorize using the
markoverwith mechanism}
\end{document}
正如文档中所述ulem
,这不是一个“真正灵活”的规则,但在这种情况下感觉不可能,并且通过重复许多小片段来绘制规则。
soul
这个缺点与上面链接的包中的解决方案相同。