4

The dirtree package uses a . followed by a whitespace as a sign to end a node. See documentation, page 2

This usually works pretty good, but I'd like to print correct format e.g. DD.MM.YYYY as a node for my DirTree. This causes a problem as the character sequence e.g.[SPACE] seems to be interpreted as the termination sequence.

The error messages read Use of \next doesn't match its definition and Undefined control sequence

Is there a way to print [dot][space] without attempting to end the node? If there is none, are there other characters which can act as a space?

MWE to quickly reproduce:

\documentclass[]{article}
\usepackage{dirtree}

\begin{document}
  \dirtree{%
    .1 ROOT.
    .2 Level 2.
    .2 Correct format e.g. DD.MM.YYYY.
  }
\end{document}

The question file extensions in dirtree is related but the OP can remove the space after the dot, which I can not.

Nijin22
  • 342

2 Answers2

4

One solution is to change every trailing space after a period to ~ or \+space, as shown here.

\documentclass[]{article}
\usepackage{dirtree}

\begin{document}
  \dirtree{%
    .1 ROOT.
    .2 Level 2.
    .2 Correct format e.g.~DD.MM.YYYY. %% or e.g.\ DD.MM.YYYY.
}
\end{document}
Richard
  • 2,084
  • 2
    Great answer, thanks! To add to this: It seems simply replacing the space with ~ seems to work as well and keeps the code a bit more simple – Nijin22 May 20 '16 at 07:05
  • 1
    Oh, so it does! I thought I tried that, but I guess not. I'll fix the answer. – Richard May 20 '16 at 07:05
  • 1
    Note that ~ prevent line breaking at that particular space. On the other hand, I don't know whether line breaking is feasible at all inside the \dirtree. – Henri Menke May 23 '16 at 06:59
4

You could nest the expression containing dots in braces to “hide” them.

\documentclass{article}
\usepackage{dirtree}
\begin{document}
  \dirtree{%
    .1 ROOT.
    .2 Level 2.
    .2 Correct format {e.g. DD.MM.YYYY}.
  }
\end{document}

It is also possible to introduce braces for all the nodes in the tree to convey a notion of consistency.

\documentclass{article}
\usepackage{dirtree}
\begin{document}
  \dirtree{%
    .1 {ROOT}.
    .2 {Level 2}.
    .2 {Correct format e.g. DD.MM.YYYY}.
  }
\end{document}

The result is always the same.

enter image description here

Henri Menke
  • 109,596