如何在 tikz 示例中调整虚线

如何在 tikz 示例中调整虚线

我看见在某些文本下方添加虚线。但我想知道如何将其向下移动一点并调整其位置,我不知道如何从示例中调整其布局。

我还想知道如何简单地添加“空白行”,基本上在文本中像这样:

Hello this is some text with a ___________ blank line.

我尝试这样做,但似乎不正确并且不起作用:

Hello this is some text with a \thedot{          } blank line.

\newcommand{\thedot}[1]{%
  \tikz[baseline=(todotted.base)]{
    \node[inner sep=1pt,outer sep=0pt] (todotted) {#1};
    \draw[dotted, thick] (todotted.south west) -- (todotted.south east);
  }%
}%

我根据当前的答案得出了这一结论:

在此处输入图片描述

当我这样做\node[inner sep=1pt,outer sep=0pt,xshift=-2mm]\tikz[baseline=2mm]。仍然不正确。

答案1

使用 tikz 时,只需使用baseline键,请参阅手册 3.0.1a 的第 124 页。我给线条涂上颜色,使代码更易于阅读。

回复你的最后一条评论:

baseline 在第 124 页的定义如下:

/tikz/baseline=< dimension or coordinate or default >

因此,我们本质上可以使用坐标或维度,但不能同时使用两者。要同时应用两者,transform canvas={yshift=-2pt}可以按以下方式应用:

\tikz[baseline=(todotted.base)]\path[red, dash dot dot,transform canvas={yshift=-2pt}] node  (todotted) {} edge ([xshift=2cm]todotted){};

代码和结果:

  \documentclass{article}
\usepackage{tikz}
\begin{document}
Hello this is some text with a \tikz[baseline]\draw[dashed](0,0)--+(1,0); blank line.

Hello this is some text with a \tikz[baseline=-2mm]\draw[red,thick,densely dotted](0,0)--+(1,0); blank line.

Hello this is some text with a \tikz[baseline=1mm]\draw[blue,thick,dotted](0,0)--+(1,0); blank line.

Hello this is some text with a \tikz[baseline=(todotted.base)]\path[cyan, loosely dash dot ] node  (todotted) {} edge ([xshift=2cm]todotted){}; blank line.

Hello this is some text with a \tikz[baseline=(todotted.base)]\path[red, dash dot dot,transform canvas={yshift=-2pt}] node  (todotted) {} edge ([xshift=2cm]todotted){}; blank line.

\end{document} 

在此处输入图片描述

答案2

实线:命令是\rule[lift]{width}{thickness}

Hello this is some text with a \rule[0pt]{1cm}{.4pt} blank line.

Hello this is some text with a \rule[2pt]{1cm}{.4pt} blank line.

Hello this is some text with a \rule[-2pt]{1cm}{.4pt} blank line.

在此处输入图片描述

虚线:使用一个框,我们定义一个以宽度作为参数的新命令。

\documentclass[11pt,a4paper]{report}

\newcommand{\dottedline}[1]{\makebox[#1]{\dotfill}}
\begin{document}
Hello this is some text with a \dottedline{2cm}  blank line.

Hello this is some text with a \dottedline{3cm}  blank line.
\end{document}

![在此处输入图片描述

编辑:

在此处输入图片描述

您可以更改5mm值(点之间的距离)和{\Large .}(用于填充的符号)。

\documentclass[11pt,a4paper]{report}

\makeatletter
\def\mydotsfill{\leavevmode \cleaders \hb@xt@ 5mm{\hss {\Large .}\hss }\hfill \kern \z@}
\newcommand{\dottedline}[1]{\makebox[#1]{\mydotsfill}}
\makeatother


\begin{document}
Hello this is some text with a \dottedline{2cm}  blank line.

Hello this is some text with a \dottedline{3cm}  blank line.

\end{document}

编辑2:另一个版本,您可以给出一个可选参数,其中的文本将插入到点的上方,并居中。

在此处输入图片描述

\documentclass[11pt,a4paper]{report}
\usepackage{graphicx}

\makeatletter
\def\mydotsfill{\leavevmode \cleaders \hb@xt@ 3mm{\hss {\Large .}\hss }\hfill \kern \z@}
\newcommand{\dottedline}[2][]{\makebox[#2]{\mydotsfill\makebox[0pt]{\raisebox{.75ex}{#1}}\mydotsfill}}
\makeatother


\begin{document}
Hello this is some text with a \dottedline[December]{5cm}  blank line.

Hello this is some text with a \dottedline{3cm}  blank line.

\end{document}

相关内容