Graphics, Figures & TablesTikz Subfigure (\includegraphics) overlaps with text

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
Poebelchen
Posts: 3
Joined: Thu Apr 29, 2021 3:00 pm

Tikz Subfigure (\includegraphics) overlaps with text

Post by Poebelchen »

I have created a tikz figure entailing 3 subfigures in 2 rows. The first row entails an image while the other has two bar graphs next to each other.

- It can be typesetted in Overleaf

My problem: The imported image overlaps with the text above the figure


Code: Select all

\documentclass{article}
\usepackage[utf8]{inputenc}
 \usepackage{pgfplots}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.7}
\usepackage{tikz}
\usepackage{graphicx}
\usepackage{subcaption}
\usepackage{lipsum}


\title{Example}
\author{Name }
\date{April 2021}

\begin{document}

\maketitle

\section{Introduction}
\lipsum[1-5]

    \begin{figure}[h]
\centering
\resizebox{\columnwidth}{!}{%
\begin{subfigure}[b]{0.9\linewidth}
    \begin{tikzpicture}
\includegraphics[width=\linewidth,height=7cm]{example-image-a.jpg}
\end{tikzpicture}
\label{fig:sub1}
    \end{subfigure}
    }
    \resizebox{\linewidth}{!}{%
    \begin{subfigure}[b]{0.45\linewidth}

\begin{tikzpicture}
\begin{axis}[
    ybar,
    domain=0:1,
    every axis plot/.append style={no markers},
    %xlabel=Timepoints (d),
    ylabel= Label,
    width=\linewidth,
    height=7cm,
    ymax=700,
    ymin=150,
    xmin=-0.5,
    xmax=1.5,
    xticklabels={DIV15, DIV17},xtick={0,1},
    x tick label style={rotate=90}, 
    legend style={at={(0.45,0.78)},anchor=west}]
\addplot+[fill,error bars/.cd,
    y dir=both,y explicit]
    coordinates {
    (0,490.40) +- (23.86,23.86) 
    (1,376.00) +- (22.19,22.19) 
    };
\addplot+[fill,error bars/.cd,
    y dir=both,y explicit] 
    coordinates {
    (0,386.30) +- (41.29,41.29) 
    (1,329.90) +- (32.07,32.07)
    };  
\addplot+[fill,error bars/.cd,
    y dir=both,y explicit] 
    coordinates {
    (0,424.60) +- (24.90,24.90) 
    (1,334.90) +- (20.09,20.09)
    };  
\addplot+[fill,error bars/.cd,
    y dir=both,y explicit] 
    coordinates {
    (0,263.2) +- (33.89,33.89) 
    (1,228.00) +- (30.67,30.67)
    };  
\node [above, font=\Large] at (axis cs: 0.21,300) {$\ast$}; 
\node [above, font=\Large] at (axis cs: 1.21,265) {$\ast$}; 
\legend{1,2,3,4}
\end{axis}
\end{tikzpicture}   

    \end{subfigure}\hspace{8mm}
    
    
\begin{subfigure}[b]{0.5\linewidth}
    \begin{tikzpicture}
\begin{axis}[
    ybar,
    %bar width=.45cm,
    domain=0:1,
    every axis plot/.append style={no markers},
    ylabel= Label,
    width=\linewidth,
    height=7cm,
    ymax=7,
    ymin=0,
    xmin=-0.5,
    xmax=1.5,
    xticklabels={DIV15, DIV17},xtick={0,1},
    x tick label style={rotate=90}, 
    legend style={at={(0.45,0.78)},anchor=west}]
\addplot+[fill,error bars/.cd,
    y dir=both,y explicit]
    coordinates {
    (0,3.69) +- (0.17,0.17) 
    (1,4.16) +- (0.28,0.28) 
    };
\addplot+[fill,error bars/.cd,
    y dir=both,y explicit] 
    coordinates {
    (0,3.29) +- (0.31,0.31) 
    (1,3.36) +- (0.26,0.26)
    };  
\addplot+[fill,error bars/.cd,
    y dir=both,y explicit] 
    coordinates {
    (0,3.70) +- (0.11,0.11) 
    (1,4.10) +- (0.25,0.25)
    };  
\addplot+[fill,error bars/.cd,
    y dir=both,y explicit] 
    coordinates {
    (0,2.32) +- (0.30,0.30) 
    (1,3.11) +- (0.25,0.25)
    };  
\node [above, font=\Large] at (axis cs: 0.21,2.8) {$\ast$}; 
\node [above, font=\Large] at (axis cs: 1.21,3.6) {$\ast$}; 
\end{axis}
\end{tikzpicture}   
    \end{subfigure}}
    \caption[Caption]{Caption\\
\footnotesize{\textit{Note.}}}
    \label{fig:3.5}
\end{figure}

\end{document}

Thank you!
Last edited by Poebelchen on Thu Apr 29, 2021 4:57 pm, edited 3 times in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX books
User avatar
Ijon Tichy
Posts: 640
Joined: Mon Dec 24, 2018 10:12 am

Tikz Subfigure (\includegraphics) overlaps with text

Post by Ijon Tichy »

First of all: Your example is not working because of the character before \documentclass. Please fix it.

Neither the first tikzpicuture nor the \resizebox commands doesn't make sense here. subfigure without \caption also doesn't make much sense.

Code: Select all

\documentclass{article}
\usepackage[utf8]{inputenc}
 \usepackage{pgfplots}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.7}
\usepackage{tikz}
\usepackage{graphicx}
%\usepackage{subcaption}% Not used in this example.
\usepackage{lipsum}

\title{Example}
\author{Name }
\date{April 2021}

\begin{document}

\maketitle

\section{Introduction}
\lipsum[1-5]

    \begin{figure}[h]
\centering
%\resizebox{\columnwidth}{!}{%
%\begin{subfigure}[b]{0.9\linewidth}
%    \begin{tikzpicture}
\includegraphics[width=\linewidth,height=7cm]{example-image-a.jpg}
%\end{tikzpicture}
\label{fig:sub1}
%    \end{subfigure}
%    }

%\resizebox{\linewidth}{!}{%
    \begin{minipage}[b]{0.45\linewidth}
\begin{tikzpicture}
\begin{axis}[
    ybar,
    domain=0:1,
    every axis plot/.append style={no markers},
    %xlabel=Timepoints (d),
    ylabel= Label,
    width=\linewidth,
    height=7cm,
    ymax=700,
    ymin=150,
    xmin=-0.5,
    xmax=1.5,
    xticklabels={DIV15, DIV17},xtick={0,1},
    x tick label style={rotate=90}, 
    legend style={at={(0.45,0.78)},anchor=west}]
\addplot+[fill,error bars/.cd,
    y dir=both,y explicit]
    coordinates {
    (0,490.40) +- (23.86,23.86) 
    (1,376.00) +- (22.19,22.19) 
    };
\addplot+[fill,error bars/.cd,
    y dir=both,y explicit] 
    coordinates {
    (0,386.30) +- (41.29,41.29) 
    (1,329.90) +- (32.07,32.07)
    };  
\addplot+[fill,error bars/.cd,
    y dir=both,y explicit] 
    coordinates {
    (0,424.60) +- (24.90,24.90) 
    (1,334.90) +- (20.09,20.09)
    };  
\addplot+[fill,error bars/.cd,
    y dir=both,y explicit] 
    coordinates {
    (0,263.2) +- (33.89,33.89) 
    (1,228.00) +- (30.67,30.67)
    };  
\node [above, font=\Large] at (axis cs: 0.21,300) {$\ast$}; 
\node [above, font=\Large] at (axis cs: 1.21,265) {$\ast$}; 
\legend{1,2,3,4}
\end{axis}
\end{tikzpicture}   
\end{minipage}%
%\hspace{8mm}
\hfill
\begin{minipage}[b]{0.5\linewidth}
    \begin{tikzpicture}
\begin{axis}[
    ybar,
    %bar width=.45cm,
    domain=0:1,
    every axis plot/.append style={no markers},
    ylabel= Label,
    width=\linewidth,
    height=7cm,
    ymax=7,
    ymin=0,
    xmin=-0.5,
    xmax=1.5,
    xticklabels={DIV15, DIV17},xtick={0,1},
    x tick label style={rotate=90}, 
    legend style={at={(0.45,0.78)},anchor=west}]
\addplot+[fill,error bars/.cd,
    y dir=both,y explicit]
    coordinates {
    (0,3.69) +- (0.17,0.17) 
    (1,4.16) +- (0.28,0.28) 
    };
\addplot+[fill,error bars/.cd,
    y dir=both,y explicit] 
    coordinates {
    (0,3.29) +- (0.31,0.31) 
    (1,3.36) +- (0.26,0.26)
    };  
\addplot+[fill,error bars/.cd,
    y dir=both,y explicit] 
    coordinates {
    (0,3.70) +- (0.11,0.11) 
    (1,4.10) +- (0.25,0.25)
    };  
\addplot+[fill,error bars/.cd,
    y dir=both,y explicit] 
    coordinates {
    (0,2.32) +- (0.30,0.30) 
    (1,3.11) +- (0.25,0.25)
    };  
\node [above, font=\Large] at (axis cs: 0.21,2.8) {$\ast$}; 
\node [above, font=\Large] at (axis cs: 1.21,3.6) {$\ast$}; 
\end{axis}
\end{tikzpicture}   
\end{minipage}
%}
    \caption[Caption]{Caption\\
\footnotesize{\textit{Note.}}}
    \label{fig:3.5}
\end{figure}

\end{document}
Please also note, LaTeX automatically replaces figure option h by ht. So option h does not make much sense. I would recommend to use at least hp or htp.
Sorry, but I can no longer participate here as the administrator is trampling on my wishes on one of his other platforms. :cry:
Poebelchen
Posts: 3
Joined: Thu Apr 29, 2021 3:00 pm

Tikz Subfigure (\includegraphics) overlaps with text

Post by Poebelchen »

Thanks for your advice. However, if I run your example the 2 bar graph below each other instead of next to each other.

Also the use of minipage produces problems with the margins and text when used with such large figures. I.e. now the caption is only half visible.
User avatar
Ijon Tichy
Posts: 640
Joined: Mon Dec 24, 2018 10:12 am

Tikz Subfigure (\includegraphics) overlaps with text

Post by Ijon Tichy »

Poebelchen wrote:Thanks for your advice. However, if I run your example the 2 bar graph below each other instead of next to each other.
If I click to the Run LaTeX here button, the two bar graphs are next to each other. So I cannot reproduce your problem. Sorry.
Sorry, but I can no longer participate here as the administrator is trampling on my wishes on one of his other platforms. :cry:
User avatar
Stefan Kottwitz
Site Admin
Posts: 10310
Joined: Mon Mar 10, 2008 9:44 pm

Tikz Subfigure (\includegraphics) overlaps with text

Post by Stefan Kottwitz »

Hi Poebelchen,

welcome to the forum!
Poebelchen wrote:if I run your example the 2 bar graph below each other instead of next to each other.
Also for me it's next to each other. What do you do differently? Perhaps post the .log file as attachment here, if you really run the same code. Perhaps there's an error message (that Overleaf doesn't show you or you don't noticed it) and it compiles anyway but with broken output.
Poebelchen wrote:Also the use of minipage produces problems with the margins and text when used with such large figures. I.e. now the caption is only half visible.
That's theoretically somehow, not seen in the example. Would you like to post adjusted code that shows the issue? Your example code in the first post was already very good to see and to test for the first issue.

Stefan
LaTeX.org admin
Poebelchen
Posts: 3
Joined: Thu Apr 29, 2021 3:00 pm

Tikz Subfigure (\includegraphics) overlaps with text

Post by Poebelchen »

Stefan Kottwitz wrote:Hi Poebelchen,

welcome to the forum!
Poebelchen wrote:if I run your example the 2 bar graph below each other instead of next to each other.
Also for me it's next to each other. What do you do differently? Perhaps post the .log file as attachment here, if you really run the same code. Perhaps there's an error message (that Overleaf doesn't show you or you don't noticed it) and it compiles anyway but with broken output.
Poebelchen wrote:Also the use of minipage produces problems with the margins and text when used with such large figures. I.e. now the caption is only half visible.
That's theoretically somehow, not seen in the example. Would you like to post adjusted code that shows the issue? Your example code in the first post was already very good to see and to test for the first issue.

Stefan
Hi Stefan, thanks you!
I have by now solved the issues mentioned above. Apparently it worked after I restarted my computer, so maybe there were some intermediates from the old version during the first attempt.

F
Post Reply