1

I usually produce my plots through pgfplots. However, I have an alignment problem in the twocolumn environment. Indeed, if I produce only one graph it results correctly aligned to the column. When I do this in a subfloat environment the graphs are not aligned to the single graph. I would like to know if there is a way to align the plots in the subfloat environment to the single graphs. Moreover, the size of the effective graph (without considering the labels) depends on the labels themselves (for example when the label contains an integral sign). Is there a way to fix the size of the "effective" graph?

Below and example for clarification

enter image description here

\documentclass[twocolumn,10pt]{article}

\usepackage{blindtext}
\usepackage{graphicx}
\usepackage{subcaption}
\usepackage{pgfplots}


\begin{document}

\begin{figure*}[!h]
\centering
\subfloat[graph A]
{
\begin{tikzpicture}
\begin{axis}[
    width=0.36\textwidth,
    height=0.27\textwidth,
]

\addplot [
    domain=-10:10, 
    samples=100, 
    color=red,
]{x^2 - 2*x - 1};
\addlegendentry{\(x^2 - 2x - 1\)}


\end{axis}
\end{tikzpicture}}
%\hspace{3cm}
\subfloat[graph B]
{\label{fig:totalTemperatureAmp}
\begin{tikzpicture}
\begin{axis}[
    width=0.36\textwidth,
    height=0.27\textwidth,
]

\addplot [
    domain=-10:10, 
    samples=100, 
    color=red,
]{x^2 - 2*x - 1};
\addlegendentry{\(x^2 - 2x - 1\)}


\end{axis}
\end{tikzpicture}}
\caption{graph in subfloat enviroment}
\label{fig:amplitudeBC}
\end{figure*}


\begin{figure}[!t]
\centering
\begin{tikzpicture}
\begin{axis}[
    width=0.36\textwidth,
    height=0.27\textwidth,
]

\addplot [
    domain=-10:10, 
    samples=100, 
    color=red,
]{x^2 - 2*x - 1};
\addlegendentry{\(x^2 - 2x - 1\)}


\end{axis}
\end{tikzpicture}
\caption{graph in figure enviroment}
\label{fig:pm}
\end{figure}



\blindtext \blindtext \blindtext \blindtext \blindtext \blindtext \blindtext \blindtext \blindtext \blindtext \blindtext \blindtext \blindtext \blindtext \blindtext \blindtext


\end{document}
1
  • Try to nest the subfloats in a strip environment, from the cuted package (stt bundle). It should appear at the top of the following page.
    – Bernard
    Jun 21, 2021 at 12:52

1 Answer 1

2

You can try using two subfigure environments, and set their width to \columnwidth, with an \hfill between them. Note I also used \columnwidth for the axis size.

Regarding your last question, are you perhaps after the scale only axis option? I.e., with \begin{axis}[scale only axis, width=5cm], the 5cm determine the size of the axis box alone, without labels.

\documentclass[twocolumn,10pt]{article}

\usepackage{blindtext}
\usepackage{subcaption}
\usepackage{pgfplots}


\begin{document}

\begin{figure*}[!h]
\begin{subfigure}{\columnwidth}
\centering
\begin{tikzpicture}
\begin{axis}[
    width=0.8\columnwidth,
    height=0.6\columnwidth,
]

\addplot [
    domain=-10:10, 
    samples=100, 
    color=red,
]{x^2 - 2*x - 1};
\addlegendentry{\(x^2 - 2x - 1\)}
\end{axis}
\end{tikzpicture}
\caption{Graph A}
\end{subfigure}
\hfill
\begin{subfigure}{\columnwidth}
\centering
\begin{tikzpicture}
\begin{axis}[
    width=0.8\columnwidth,
    height=0.6\columnwidth,
]

\addplot [
    domain=-10:10, 
    samples=100, 
    color=red,
]{x^2 - 2*x - 1};
\addlegendentry{\(x^2 - 2x - 1\)}
\end{axis}
\end{tikzpicture}
\caption{graph B}
\label{fig:totalTemperatureAmp}
\end{subfigure}
\caption{graph in subfloat enviroment}
\label{fig:amplitudeBC}
\end{figure*}


\begin{figure}[!t]
\centering
\begin{tikzpicture}
\begin{axis}[
    width=0.8\columnwidth,
    height=0.6\columnwidth,
]

\addplot [
    domain=-10:10, 
    samples=100, 
    color=red,
]{x^2 - 2*x - 1};
\addlegendentry{\(x^2 - 2x - 1\)}


\end{axis}
\end{tikzpicture}
\caption{graph in figure enviroment}
\label{fig:pm}
\end{figure}



\blindtext \blindtext \blindtext \blindtext \blindtext \blindtext \blindtext \blindtext \blindtext \blindtext \blindtext \blindtext \blindtext \blindtext \blindtext \blindtext


\end{document}
1
  • Thank you very much for the time you spent writing the solution. That's exactly what I wanted for both the problems.
    – Fly
    Jun 22, 2021 at 8:02

You must log in to answer this question.

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