2

I have the following problem. I would like to use a tikz picture in an equation environment. The following is a minimal example:

\documentclass{article}
\usepackage{tikz}
\usepackage{amsmath}

\begin{document} Some text here. \begin{equation*} \left[ \begin{tikzpicture} \draw[thick] (1, -1) .. controls (0.4, -1) and (0, -0.6) .. (0, 0); \draw[thick] (0, 0) .. controls (0, 0.6) and (0.6, 1) .. (1, 1); \draw[thick] (1, -0.5) .. controls (0.7, -0.5) and (0.5, -0.3) .. (0.5, 0); \draw[thick] (0.5, 0) .. controls (0.5, 0.3) and (0.7, 0.5) .. (1, 0.5);

\draw[thick] (1, -1) .. controls (1.5, -1) and (1.75, -0.6) .. (1.75, -0.25); \draw[thick] (1, 0.5) .. controls (1.5, 0.5) and (1.75, 0.1) .. (1.75, -0.25); \draw[thick] (1, -0.5) .. controls (1.5, -0.5) and (1.75, -0.1) .. (1.75, 0.25); \draw[thick] (1, 1) .. controls (1.5, 1) and (1.75, 0.6) .. (1.75, 0.25);

\draw[dashed] (1, -1.1) -- (1, 1.1); \end{tikzpicture} \right] \end{equation*} Some more text here \end{document}

Now if I delete the "\left[ ... \right]", then it looks as expected:

enter image description here

But the result of the code above looks unexpected to me:

enter image description here

It looks as if the image would contain another white space under the actual graphic, which is not shown without the brackets. How can I get rid of this space?

  • Your image is all above the baseline. Try \begin{tikzpicture}[baseline]... (sorry, the previous comment was wrong in this case, but https://tex.stackexchange.com/questions/290357/tikz-bounding-box-cropping-too-much-space-for-curves still could be related for other figures) – Rmano May 10 '21 at 14:19
  • Try [baseline=(current bounding box.center)]. You will still be off by {0.5\ht\strutbox-0.5\dp\strutbox} though. – John Kormylo May 10 '21 at 17:56
  • Thanks, this worked. If you post this as an answer, I can accept. – user241819 May 10 '21 at 20:17

1 Answers1

1

enter image description here Since you are loading amsmath, one solution is to use the environment bmatrix to obtain the left and right brackets. You may leave then your TikZ code as it is.

The code

\documentclass{article}
\usepackage{tikz}
\usepackage{amsmath}
\usepackage{lipsum}

\begin{document} \lipsum[1] \begin{equation*} \begin{bmatrix} \begin{tikzpicture} \draw[thick] (1, -1) .. controls (0.4, -1) and (0, -0.6) .. (0, 0); \draw[thick] (0, 0) .. controls (0, 0.6) and (0.6, 1) .. (1, 1); \draw[thick] (1, -0.5) .. controls (0.7, -0.5) and (0.5, -0.3) .. (0.5, 0); \draw[thick] (0.5, 0) .. controls (0.5, 0.3) and (0.7, 0.5) .. (1, 0.5);

  \draw[thick] (1, -1) .. controls (1.5, -1) and (1.75, -0.6) .. (1.75, -0.25);
  \draw[thick] (1, 0.5) .. controls (1.5, 0.5) and (1.75, 0.1) .. (1.75, -0.25);
  \draw[thick] (1, -0.5) .. controls (1.5, -0.5) and (1.75, -0.1) .. (1.75, 0.25);
  \draw[thick] (1, 1) .. controls (1.5, 1) and (1.75, 0.6) .. (1.75, 0.25);

  \draw[dashed] (1, -1.1) -- (1, 1.1);
\end{tikzpicture}   

\end{bmatrix} \end{equation*} \lipsum[2] \end{document}

Daniel N
  • 5,687