1

I am attempting to draw the dimension of a line segment for my tkz-euclide drawing while in tabular environment. For some reason this results in an error. It should be noted, that I do not have any problems with including tkz-euclide drawings in tabular environment. The error arises only when the dim parameter is used.

Here is a minimal example that results in an error:

\documentclass[a4paper, 11pt]{article}
\usepackage{tkz-euclide}

\begin{document}
    \begin{tabular}{c}
        \begin{tikzpicture}
            \tkzDefPoint(0,0){A}
            \tkzDefPoint(5,0){B}
            \tkzDrawPoints(A,B)
            % Excluding the following line removes the error
            \tkzDrawSegment[dim={$5\mathrm m$, 12pt,}](A,B)
        \end{tikzpicture}
    \end{tabular}
\end{document}

However, the same tikz drawing works while outside of the tabular environment. For example, the following code works without any issues:

\documentclass[a4paper, 11pt]{article}
\usepackage{tkz-euclide}

\begin{document}
    \begin{tikzpicture}
        \tkzDefPoint(0,0){A}
        \tkzDefPoint(5,0){B}
        \tkzDrawPoints(A,B)
        \tkzDrawSegment[dim={$5\mathrm m$, 12pt,}](A,B)
    \end{tikzpicture}
\end{document}

Apart from the tabular environment I have also tried tabu and tabularx – the error still persists.

What could have caused this error, and how I could circumnavigate it? Ideally, I would like to continue working with tkz-euclide rather than defining my own 'dim' equivalent, but any solution is welcome!

Thanks!

2
  • 3
    don't use the tabu package. It is broken and unmaintained. Aug 7, 2021 at 13:50
  • @UlrikeFischer Thanks, I will try to look for alternatives! However, the issue still persists when using tabular or tabularx instead.
    – Spuu
    Aug 7, 2021 at 13:54

1 Answer 1

2

What could have caused this error? Well, some interference of tkz-euclide with tabular, probably not worth to investigate (except if you are the maintainer of tkz-euclide).

How to circumvent the problem? I found that in most cases of such interferences, the following method works:

  1. Define a \newsavebox, e.g. \newsavebox\mydrawing

  2. Use \savebox to typeset the contents interfering with the outer environment into this box, e.g.,

    \savebox\mydrawing{\begin{tikzpicture}...\end{tikzpicture}}
    
  3. Use the box instead of the original contents, e.g., \usebox\mydrawing

enter image description here

\documentclass{article}
\usepackage{tkz-euclide}

\newsavebox\mydrawing
\savebox\mydrawing{%
  \begin{tikzpicture}
  \tkzDefPoint(0,0){A}
  \tkzDefPoint(5,0){B}
  \tkzDrawPoints(A,B)
  \tkzDrawSegment[dim={$5\mathrm m$, 12pt,}](A,B)
  \end{tikzpicture}%
}

\begin{document}
before
\begin{tabular}{c}
  above\\
  \usebox\mydrawing\\
  below
\end{tabular}
after
\end{document}
1
  • Genius! Thanks for that,very clever solution. I think, anyway, that Alain Matthes should take a look at this weird interference.
    – SebGlav
    Aug 7, 2021 at 16:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .