3

In a twosided ClassicThesis document, I want to put 2 TikZ pictures side by side, so that their total width is bigger than \textwidth.

If I use KOMA's addmargin as described in this question, the subfigures just ignore it. Memoir's \centerfloat from this question doesn't actually center the figures. \makebox from the last question with subfigures seems too complicated because I will need to make a box in every subfigure.

How to center a wide figure in ClassicThesis relative to the whole page? That is, I want to have a margin of, say, 1 cm on the left, and the same 1 cm on the right.

Upd: The answer below is valid to get absolute centering if used with different inner and outer margin adjustments, like begin{addmargin*}[-0.1\textwidth]{-0.3\textwidth}

\documentclass[
twoside,
openright
]{scrreprt}

\usepackage{filecontents}
\begin{filecontents}{pic.tikz}
    \begin{tikzpicture}
    \begin{axis}[
    xmin=3.75, xmax=4.75,
    ]
    \end{axis}
    \end{tikzpicture}%
\end{filecontents}

\usepackage{subcaption, tikz, pgfplots}
\pgfplotsset{compat=1.6,
    width=\textwidth,
    height=0.25\textheight,
    tick label style={font=\tiny},
    legend style={font=\tiny, at={(0.0,1.05)}, anchor=south west},
    legend columns=10,
    xlabel shift={-1ex},
    xlabel style={font=\tiny},
    ylabel shift={-1em},
    ylabel style={font=\tiny},
}%

\makeatletter
\newcommand*{\centerfloat}{%
    \parindent \z@
    \leftskip \z@ \@plus 0fil \@minus \textwidth
    \rightskip\leftskip
    \parfillskip \z@skip}
\makeatother

\begin{document}
Text width. Text width. Text width. Text width. Text width. Text width.  
\begin{addmargin*}[-3em]{-4em}
Text for testing margins. Text for testing margins. Text for testing margins. Text for testing margins.
\begin{figure}[h]
        \centerfloat
    \begin{subfigure}[b]{0.65\textwidth}
        \input{pic.tikz}%
        \caption{Left picture}
    \end{subfigure}
    ~
    \begin{subfigure}[b]{0.65\textwidth}
        \input{pic.tikz}%
        \caption{Right picture}
    \end{subfigure}
\end{figure}
\end{addmargin*}

\clearpage
    Text for testing margins. Text for testing margins. Text for testing margins. Text for testing margins.
    \begin{figure}[h]
        \centerfloat
        \begin{subfigure}[b]{0.65\textwidth}
            \input{pic.tikz}%
            \caption{Left picture}
        \end{subfigure}
        ~
        \begin{subfigure}[b]{0.65\textwidth}
            \input{pic.tikz}%
            \caption{Right picture}
        \end{subfigure}
    \end{figure}

\end{document}
3

Note that pgfplots option width=\textwidth means that the axis itself are \textwidth-45pt wide. The remainig 45pt are reserved for the axis labels and tick labels. The real wide of these labels is not taken into account. In your example both pictures are smaller than .65\textwidth. Therefore you have to use \raggedleft in for the left picture and \raggedright for the right.

\begin{filecontents}{pic.tikz}
\begin{tikzpicture}
\begin{axis}[
xmin=3.75, xmax=4.75,
ymin=-1,ymax=5
]
\end{axis}
\end{tikzpicture}%
\end{filecontents}

\documentclass[
twoside,
openright
]{scrreprt}
\usepackage{showframe}% to show the page layout
\usepackage{lipsum}% only for dummy text

\usepackage{subcaption}
\usepackage{pgfplots}% loads also tikz, ...
\pgfplotsset{compat=1.6,% really 1.6? current version is 1.16
    width=\linewidth,% <- changed
    height=0.25\textheight,
    tick label style={font=\tiny},
    legend style={font=\tiny, at={(0.0,1.05)}, anchor=south west},
    legend columns=10,
    xlabel shift={-1ex},
    xlabel style={font=\tiny},
    ylabel shift={-1em},
    ylabel style={font=\tiny},
}%

\makeatletter
\newcommand*{\centerfloat}{%
    \parindent \z@
    \leftskip \z@ \@plus 0fil \@minus \textwidth
    \rightskip\leftskip
    \parfillskip \z@skip}
\makeatother

\begin{document}
\lipsum[1]
\begin{figure}[hb]
  \centerfloat
  \begin{subfigure}[b]{0.65\textwidth}
      \raggedleft% <- added
      \input{pic.tikz}%
      \caption{Left picture}
  \end{subfigure}%
  ~
  \begin{subfigure}[b]{0.65\textwidth}
      \raggedright% <- added
      \input{pic.tikz}%
      \caption{Right picture}
  \end{subfigure}
\end{figure}
\lipsum[2]
\end{document}

Result:

enter image description here


If you want to use addmargin*, this evironment must be used inside the figure environment:

\begin{filecontents}{pic.tikz}
\begin{tikzpicture}
\begin{axis}[
xmin=3.75, xmax=4.75,
ymin=-1,ymax=5
]
\end{axis}
\end{tikzpicture}%
\end{filecontents}

\documentclass[
twoside,
openright
]{scrreprt}
\usepackage{showframe}% to show the page layout
\usepackage{lipsum}% only for dummy text

\usepackage{subcaption}
\usepackage{pgfplots}% loads also tikz, ...
\pgfplotsset{compat=1.6,% really 1.6? current version is 1.16
    width=\linewidth,% <- changed
    height=0.25\textheight,
    tick label style={font=\tiny},
    legend style={font=\tiny, at={(0.0,1.05)}, anchor=south west},
    legend columns=10,
    xlabel shift={-1ex},
    xlabel style={font=\tiny},
    ylabel shift={-1em},
    ylabel style={font=\tiny},
}%

\begin{document}
\lipsum[1]
\begin{figure}[hb]
  \begin{addmargin}{-.2\textwidth}
    \centering
    \begin{subfigure}[b]{0.65\textwidth}
        \raggedleft% <- added
        \input{pic.tikz}%
        \caption{Left picture}
    \end{subfigure}%
    ~
    \begin{subfigure}[b]{0.65\textwidth}
        \raggedright% <- added
        \input{pic.tikz}%
        \caption{Right picture}
    \end{subfigure}
  \end{addmargin}
\end{figure}
\lipsum[2]
\end{document}

Result:

enter image description here

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.