3

I tried to place two tikzpictures in one figure as two subfigures, but the tikzpicture did not draw properly in subfigure. I have tried package subfig, subfigure, subcaption, they all failed.

\documentclass[UTF8]{article}

\usepackage{subfig}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{datavisualization}
\usetikzlibrary{datavisualization.formats.functions}


\begin{document}
\begin{tikzpicture}
\datavisualization [school book axes, visualize as line]
data [headline={x, y}] {
    0, 0
    1, 1
    2, 1
    3, 0
};
\end{tikzpicture}

\begin{figure*}[!t]
\centering
\subfloat[Case I]{\begin{tikzpicture}
    \datavisualization [school book axes, visualize as line]
    data [headline={x, y}] {
        0, 0
        1, 1
        2, 1
        3, 0
    };
    \end{tikzpicture}%
\label{fig_first_case}}
\hfil
\subfloat[Case II]{\begin{tikzpicture}
    \datavisualization [school book axes, visualize as line]
    data [headline={x, y}] {
        0, 0
        1, 1
        2, 1
        3, 0
    };
    \end{tikzpicture}%
\label{fig_second_case}}
\caption{Simulation results for the network.}
\label{fig_sim}
\end{figure*}
\end{document}

And the output is as follow: enter image description here

3
  • 2
    For me the subcaption package and its subfigure environment works just fine. Could you please show how you tried using this package?
    – leandriis
    Mar 6, 2020 at 10:14
  • @leandriis Thanks for your replay. I used \subcaptionbox and failed. I tried subfigure of subcaption package as you suggested and it works just fine.
    – user208497
    Mar 6, 2020 at 12:08
  • You get the same problem if you use \sbox0{...}, but not using \setbox0=\hbox{,,,} which is supposed to be identical. I think someone has been messing around with the LaTeX kernel, and I hope like heck they aren't using expl3! Mar 6, 2020 at 14:47

1 Answer 1

1

To illustrate my comment:

Of course, it only seems to affect tikzpicture, not subfloat (which uses saveboxes to measure the width). Nor does redefining \sbox and \savebox help.

\documentclass[UTF8]{article}
\usepackage{subfig}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{datavisualization}
\usetikzlibrary{datavisualization.formats.functions}

\begin{document}
\sbox0{\begin{tikzpicture}
\datavisualization [school book axes, visualize as line]
data [headline={x, y}] {
    0, 0
    1, 1
    2, 1
    3, 0
};
\end{tikzpicture}}\usebox0% does not work right

\setbox0=\hbox{\begin{tikzpicture}
\datavisualization [school book axes, visualize as line]
data [headline={x, y}] {
    0, 0
    1, 1
    2, 1
    3, 0
};
\end{tikzpicture}}\usebox0

\begin{figure}[t]
\centering
\subfloat[Case I]{\usebox0
\label{fig_first_case}}
\hfil
\subfloat[Case II]{\usebox0
\label{fig_second_case}}
\caption{Simulation results for the network.}
\label{fig_sim}
\end{figure}
\end{document}

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.