1

I saw this to add a dotted line below some text. But I'm wondering how to shift it down a little bit and play with its positioning, I don't see how to adjust the layout of it from the example.

I would also like to know how to simply add a "blank line", basically like this in the text:

Hello this is some text with a ___________ blank line.

I tried doing this but it doesn't seem right and doesn't work:

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);
  }%
}%

I get this with the current answers:

enter image description here

When I do \node[inner sep=1pt,outer sep=0pt,xshift=-2mm] or \tikz[baseline=2mm]. Still not right.

  • 2
    Did you try using \phantom{some text} to get some blank space? – nidhin Dec 5 '18 at 19:57
  • As @nidhin says, replace thedot{ } with \thedot{\hphantom{some text}}, where some text represents the amount of space you want. Multiple spaces are ignored in text, so what you have is the equivalent of \thedot{ } (ie, a single space). The other alternative is to modify thedot macro to have a parameter which specifies the actual width of the dotted line you want to have: \thedot[2cm]{} for example. – Peter Grill Dec 5 '18 at 20:18
2

With tikz, just use the baseline key, see page 124 of manual 3.0.1a. I colored the lines to make the code easier to read.

To respond to your last comment:

baseline is defined on page 124 as follows:

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

Thus, natively we can do with either a coordinate or a dimension, but not both at the same time. To apply both at the same time, a transform canvas={yshift=-2pt} can be applied in this way:

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

Code and result:

  \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} 

enter image description here

  • It has \tikz[baseline=(todotted.base)], I'm not sure how to do essentially this: \tikz[baseline=(todotted.base) - 2pt]. – Lance Pollard Dec 5 '18 at 20:14
  • I just updated my answer – AndréC Dec 5 '18 at 20:27
  • still don't how to do an offset like in \tikz[baseline=(todotted.base) - 2pt] – Lance Pollard Dec 5 '18 at 23:13
  • I just updated my answer – AndréC Dec 6 '18 at 5:39
2

Solid line: The command is \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.

enter image description here

Dotted line: Using a box, we define a new command with width as argument.

\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}

![enter image description here

Edit:

enter image description here

You can change the 5mm value (distance between dots) and {\Large .} (the symbol to be used to fill.

\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}

Edit 2: Another version, where you can give an optional argument with the text to be inserted above the dots, centered.

enter image description here

\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}
  • I would like a dotted line if possible :) – Lance Pollard Dec 5 '18 at 20:06
  • I would like to control the spacing between the dots (make them a little tighter too) if possible :D – Lance Pollard Dec 5 '18 at 20:14
  • getting ! Undefined control sequence. \mydotsfill ->\leavevmode \cleaders \hb – Lance Pollard Dec 5 '18 at 23:12
  • I also want to be able to have text over the line in some cases. – Lance Pollard Dec 5 '18 at 23:14
  • @LancePollard, see edit 2. – Sigur Dec 6 '18 at 0:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.