1

Basically I want two tikzpictures of the same size aligned in two columns. To realise this I use the tcolorbox package with its \tcbsidebyside{}-command. The problem is that the picture in the second column has the wrong size and I have no idea why.

How can I get two tikzpictures of the same size with a small gap between them with the help of the \tscsidebyside-command?

In the following pictures the green boxes show what I'm looking for...

enter image description here

MWE

\documentclass[12pt, a4paper, parskip=full]{scrartcl}

\usepackage{tikz}
\usepackage[most]{tcolorbox}

\begin{document}
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.

\tcbsidebyside[
    sidebyside adapt=left,
    blanker,
    sidebyside gap=0.5\baselineskip,
    sidebyside align=top seam
]
{
    \begin{tikzpicture}[scale=\linewidth/20cm]
        \draw[step=1,help lines,black!20] (-4.95,-3.45) grid (4.95,3.45);
        \draw[thick] (-2.5,0) ellipse [x radius=2.25, y radius=3.4];
        \draw[thick] (2.5,0) ellipse [x radius=2.25, y radius=3.4];
    \end{tikzpicture}%
}
{
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
}

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.

\tcbsidebyside[
    sidebyside adapt=left,
    blanker,
    sidebyside gap=0.5\baselineskip,
    sidebyside align=top seam
]
{
    \begin{tikzpicture}[scale=\linewidth/20cm]
        \draw[step=1,help lines,black!20] (-4.95,-3.45) grid (4.95,3.45);
        \draw[thick] (-2.5,0) ellipse [x radius=2.25, y radius=3.4];
        \draw[thick] (2.5,0) ellipse [x radius=2.25, y radius=3.4];
    \end{tikzpicture}%
}
{
    \begin{tikzpicture}[scale=\linewidth/20cm]
        \draw[step=1,help lines,black!20] (-4.95,-3.45) grid (4.95,3.45);
        \draw[thick] (-2.5,0) ellipse [x radius=2.25, y radius=3.4];
        \draw[thick] (2.5,0) ellipse [x radius=2.25, y radius=3.4];
    \end{tikzpicture}%
}

\end{document}
1
  • The \linewidth changes inside tcbsidebyside. And due to the sidebyside adapt=left the sides are not handled in the same way. Store the linewidth outside e.g. with \newlength\mylinewidth \mylinewidth=\linewidth and then use \mylinewidth for the scale factor. Jun 28, 2016 at 9:29

2 Answers 2

5

\tcbsidebyside changes internally \linewidth, and as you are using the sidebyside adapt=left, both sides are not affected in the same way. It is better to use an independant length for the scaling.

\documentclass[12pt, a4paper, parskip=full]{scrartcl}

\usepackage{tikz}
\usepackage[most]{tcolorbox}

\newlength\mylinewidth
\AtBeginDocument{\mylinewidth=\linewidth\relax}
\begin{document}
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.

\tcbsidebyside[
    sidebyside adapt=left,
    blanker,
    sidebyside gap=0.5\baselineskip,
    sidebyside align=top seam
]
{
    \begin{tikzpicture}[scale=\mylinewidth/20cm]
        \draw[step=1,help lines,black!20] (-4.95,-3.45) grid (4.95,3.45);
        \draw[thick] (-2.5,0) ellipse [x radius=2.25, y radius=3.4];
        \draw[thick] (2.5,0) ellipse [x radius=2.25, y radius=3.4];
    \end{tikzpicture}%
}
{
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
}

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.


\tcbsidebyside[
    sidebyside adapt=left,
    blanker,
    sidebyside gap=0.5\baselineskip,
    sidebyside align=top seam
]
{
    \begin{tikzpicture}[scale=\mylinewidth/20cm]
        \draw[step=1,help lines,black!20] (-4.95,-3.45) grid (4.95,3.45);
        \draw[thick] (-2.5,0) ellipse [x radius=2.25, y radius=3.4];
        \draw[thick] (2.5,0) ellipse [x radius=2.25, y radius=3.4];
    \end{tikzpicture}%
}
{
    \begin{tikzpicture}[scale=\mylinewidth/20cm]
        \draw[step=1,help lines,black!20] (-4.95,-3.45) grid (4.95,3.45);
        \draw[thick] (-2.5,0) ellipse [x radius=2.25, y radius=3.4];
        \draw[thick] (2.5,0) ellipse [x radius=2.25, y radius=3.4];
    \end{tikzpicture}%
}

\end{document}

enter image description here

3
  • In my opinion it is better to use (\mylinewidth-0.5\baselineskip)/20cm instead of \mylinewidth/20cm as a scale factor. Am I right? PS: 0.5\baselineskip is the gap between both pictures in this case. Jun 28, 2016 at 10:50
  • Sounds ok (but I don't know where the 20cm comes from). I didn't really check, what tcolorbox is doing with \linewidth in parts. Jun 28, 2016 at 11:28
  • The width of my tikzpicture is 10cm (to be exact: 9.90cm). To scale it relativly to the linewidth someone can use e.g. scale=\linewidth/10cm (source: link). I use 20cm so that I can align two pictures next to each other. Jun 28, 2016 at 11:41
2

Although this answer does not uses \tscsidebyside as the OP explicitly requested, I'm leaving it as a reference which may be useful to other readers.

Original Answer

You don't need to use tcolorbox for the single purpose of putting things side-by-side. You can use \parbox or other standard latex environments to put blocks of text side-by-side, and you don't require any special environment to put tikzpictures side by side, but only to adjust if required the baseline of the figure.

For more info, see this question, or this answer and also the following MWE:

\documentclass[12pt, a4paper, parskip=full]{scrartcl}
\usepackage{tikz}

\begin{document}
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.

\begin{tikzpicture}[scale=\textwidth/20cm, baseline=(current bounding box.north)]
        \draw[step=1,help lines,black!20] (-4.95,-3.45) grid (4.95,3.45);
        \draw[thick] (-2.5,0) ellipse [x radius=2.25, y radius=3.4];
        \draw[thick] (2.5,0) ellipse [x radius=2.25, y radius=3.4];
\end{tikzpicture}\hspace{1mm}
\parbox[t]{0.5\textwidth}{\vskip0pt
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
}

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.


    \begin{tikzpicture}[scale=\linewidth/20cm]
        \draw[step=1,help lines,black!20] (-4.95,-3.45) grid (4.95,3.45);
        \draw[thick] (-2.5,0) ellipse [x radius=2.25, y radius=3.4];
        \draw[thick] (2.5,0) ellipse [x radius=2.25, y radius=3.4];
    \end{tikzpicture}\hspace{1mm}
    \begin{tikzpicture}[scale=\linewidth/20cm]
        \draw[step=1,help lines,black!20] (-4.95,-3.45) grid (4.95,3.45);
        \draw[thick] (-2.5,0) ellipse [x radius=2.25, y radius=3.4];
        \draw[thick] (2.5,0) ellipse [x radius=2.25, y radius=3.4];
    \end{tikzpicture}%

\end{document}

Result

0

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.