我想使用\dotuline
命令(来自ulem
包)来创建一个“填空”文档。
它给出了良好的结果,但是当空白变小时,它几乎不引人注意(以下 MWE 中的一个点):
\documentclass[a4paper,11pt]{article}
\usepackage{ulem}
\begin{document}
A sentence with a ....... to fill.
A sentence with a \dotuline{~~~~~~~} to fill.
A small ... to fill.
A small \dotuline{~~} to fill.
\end{document}
有没有办法控制这个命令的点的大小和/或密度?
答案1
\dotuline
取的定义ulem.sty
:
\def\dotuline{\bgroup
\UL@setULdepth
\markoverwith{\begingroup
\advance\ULdepth0.08ex
\lower\ULdepth\hbox{\kern.1em .\kern.04em}%
\endgroup}%
\ULon}
可以看出,负责实际点的部分是\hbox{\kern.1em .\kern.04em}
。因此,更改这些值或创建以间距为参数的宏非常容易。例如:
\documentclass[a4paper,11pt]{article}
\usepackage{ulem}
\usepackage{graphicx}
\makeatletter
\def\NewDotuline#1{\bgroup
\UL@setULdepth
\markoverwith{\begingroup
\advance\ULdepth0.08ex
\lower\ULdepth\hbox{.\kern#1}%
\endgroup}%
\ULon}
\def\SmallDotuline#1{\bgroup
\UL@setULdepth
\markoverwith{\begingroup
\advance\ULdepth0.08ex
\lower\ULdepth\hbox{\scalebox{0.7}{.}\kern#1}%
\endgroup}%
\ULon}
\makeatother
\begin{document}
\pagenumbering{gobble}
A sentence with a ....... to fill.
A sentence with a \dotuline{~~~~~~~} to fill.
A small ... to fill.
A small \dotuline{~~} to fill.
A sentence with a ....... to fill.
A sentence with a \NewDotuline{0em}{~~~~~~~} to fill.
A small ... to fill.
A small \NewDotuline{0em}{~~} to fill.
A sentence with a ....... to fill.
A sentence with a \NewDotuline{-0.1em}{~~~~~~~} to fill.
A small ... to fill.
A small \NewDotuline{-0.1em}{~~} to fill.
A sentence with a ....... to fill.
A sentence with a \SmallDotuline{-0.05em}{~~~~~~~} to fill.
A small ... to fill.
A small \SmallDotuline{-0.05em}{~~} to fill.
\end{document}
答案2
只是为了好玩:一个可配置版本的 keyval 接口\dotuline
。
现在调用该命令\ULine
,您可以修改:
- 密钥上印着什么
text
。例如,您可以使用text={\tikz[scale=0.05]\duck;}
:D text
在 withpre
和之前和之后插入的字距pos
- 下划线的深度(您可以调整深度来制作上划线——我在示例中
depth
使用了)-2ex
text={,}
可以使用可选参数在本地更改值,\ULine
或者使用在全局更改值\SetULine
。
结果:
代码:
\documentclass[a4paper,11pt]{article}
\usepackage{ulem}
\usepackage{graphicx}
\usepackage{xparse}
\usepackage{tikzducks}
\usepackage{tikzmarmots}
\ExplSyntaxOn
\keys_define:nn { uline } {
,text .code:n = \cs_set:Nn \uline_text: { #1 }
,pre .dim_set:N = \l_uline_kern_pre
,pre .initial:n = 0.1em
,pos .dim_set:N = \l_uline_kern_pos
,pos .initial:n = 0.04em
,depth .dim_set:N = \l_uline_depth
,depth .initial:n = 0.08ex
}
\NewDocumentCommand{\SetULine}{ m }
{ \keys_set:nn { uline } { #1 } }
\cs_new:Npn \uline_text: { . }
\NewDocumentCommand\ULine
{ o }
{
\c_group_begin_token
\IfValueT { #1 }
{ \keys_set:nn { uline } { #1 } }
\use:c { UL@setULdepth }
\markoverwith
{
\group_begin:
\dim_add:Nn \ULdepth { \l_uline_depth }
\box_move_down:nn { \ULdepth }
{
\hbox:n {
\tex_kern:D \l_uline_kern_pre \scan_stop:
\uline_text:
\tex_kern:D \l_uline_kern_pos \scan_stop:
}
}
\group_end:
}
\ULon
}
\ExplSyntaxOff
\begin{document}
\pagenumbering{gobble}
A sentence with a ........ to fill.
A sentence with a \ULine[pre=0pt,pos=0pt]{~~~~~~~} to fill.
A sentence with a \ULine[pre=0pt,pos=-0.1em]{~~~~~~~} to fill.
A sentence with a \ULine[text=\scalebox{0.7}{.},pre=0pt,pos=-0.05em]{~~~~~~~} to fill.
A sentence with a \ULine[depth=-2ex,text={,}]{~~~~~~~} to fill.
A sentence with a \ULine[text={\tikz[scale=0.05]\duck;},pre=-0.05em]{~~~~~~~} to fill.
A sentence with a \ULine[text={\tikz[scale=0.15]\marmot;},pre=-0.05em,depth=1ex]{~~~~~~~} to fill.
\end{document}