0

I'm trying to put two tikzpictures in two minipages, but their caption are overlapped. Here the code I'm using.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[a4paper,top=2.5cm,bottom=2.50cm,left=3.00cm,right=3.00cm]{geometry}


 \usepackage{float}
    \usepackage{wrapfig}
    \usepackage{amsmath,amssymb,commath}
    \usepackage{caption}    
    \usepackage{tikz}
    \usepackage[RPvoltages]{circuitikz}
    \usepackage{tkz-euclide}
    \usepackage{subcaption}
  
\captionsetup {
       format=plain,
       width=0.80\textwidth,
       font=normal, 
       labelfont=bf,
       figurename = Fig. ,
       tablename = Tab.
    }

    \title{\Huge{\textbf{Test}}}
    \author{me}
    \date{}
    
    \begin{document}
    
    \maketitle
    
    \begin{figure}
\centering
        \begin{minipage}{0.4\textwidth}
            \centering
            \begin{tikzpicture}
                \centering
                \draw [<->,thick] (0,2.8) node (yaxis) [left] {$t$}
                    |- (2.8,0) node (xaxis) [right] {$x$};
                \draw[thick]
                    (0,0) -- (0,-2.8)
                    (0,0) -- (-2.8,0);
                \draw[green, ultra thick] (0,-2.90) -- (0,2.90);
                \draw[dashed] 
                    (0,2.90) -- (0,2.95)
                    (0,-2.90) -- (0,-2.95);
            \end{tikzpicture}
            \captionof{figure}{Worldline of a static point-like source}
            \label{fig:static_source}
        \end{minipage}
        \begin{minipage}{0.4\textwidth}
            \centering
            \begin{tikzpicture}
                \draw [<->,thick] (0,2.8) node (yaxis) [left] {$t$}
                    |- (2.8,0) node (xaxis) [right] {$x$};
                \draw[thick]
                    (0,0) -- (0,-2.8)
                    (0,0) -- (-2.8,0);
                \node[mark size = 3pt, green] at (0,0) {\pgfuseplotmark{*}};
                \draw[dashed] 
                    (0,2.90) -- (0,2.95)
                    (0,-2.90) -- (0,-2.95);
            \end{tikzpicture}
            \captionof{figure}{Worldline of an instantaneous point-like source}
            \label{fig:inst_source}
        \end{minipage}
    \end{figure}
    
    \end{document}

Can someone help me? I see that without the caption setup it works good.

3
  • The problem is that the width is set immediately using the current value of of \textwidth. If you use [width=0.32\textwidth] or reset the width every time \textwidth changes, you will get the desired effect. Oct 19, 2020 at 15:06
  • (i) Remove line width=0.80\linewidth from caption setup. (ii) remove \centering from inside of tikzpicture (it's no harm, nor it has any benefit) and insert \hfil between minipages .
    – Zarko
    Oct 19, 2020 at 15:09
  • Maybe this one helps here: tex.stackexchange.com/questions/280822/…
    – user205700
    Oct 19, 2020 at 18:11

2 Answers 2

1
  • As I mentioned in comment, problem is your caption set up. If you like to have, that the caption width id 0.8 width of environment, where it is, than the width you need to setup in this environment.
  • In your case you not need to use \captionof since captions are inside figure float.
  • Remove command \centering inside of tikzpicture (it's no harm, nor it has any benefit)
  • Using \hfill between minipages will push them apart so that all horisontal spaces around them will be equal.

A possible MWE (in which I removed everything that has nothing to do with your problem) is:

\documentclass{article}
\usepackage[a4paper,
            hmargin=3cm, vmargin=2.5cm]{geometry}
\usepackage[T1]{fontenc}
\usepackage{caption,subcaption}
\captionsetup{ format=plain,
               labelfont=bf,
               figurename = Fig. ,
               tablename = Tab.}
\usepackage{tikz}

\begin{document}
\begin{figure}
\centering
    \begin{minipage}{0.4\textwidth}
        \centering
        \begin{tikzpicture}
            \draw [<->,thick] (0,2.8) node (yaxis) [left] {$t$}
                |- (2.8,0) node (xaxis) [right] {$x$};
            \draw[thick]
                (0,0) -- (0,-2.8)
                (0,0) -- (-2.8,0);
            \draw[green, ultra thick] (0,-2.90) -- (0,2.90);
            \draw[dashed]
                (0,2.90) -- (0,2.95)
                (0,-2.90) -- (0,-2.95);
        \end{tikzpicture}
        \captionsetup{width=0.80\textwidth}
        \caption{Worldline of a static point-like source}
        \label{fig:static_source}
    \end{minipage}\hfil
    \begin{minipage}{0.4\textwidth}
        \centering
        \begin{tikzpicture}
            \draw [<->,thick] (0,2.8) node (yaxis) [left] {$t$}
                |- (2.8,0) node (xaxis) [right] {$x$};
            \draw[thick]
                (0,0) -- (0,-2.8)
                (0,0) -- (-2.8,0);
            \node[mark size = 3pt, green] at (0,0) {\pgfuseplotmark{*}};
            \draw[dashed]
                (0,2.90) -- (0,2.95)
                (0,-2.90) -- (0,-2.95);
        \end{tikzpicture}
        \captionsetup{width=0.80\textwidth}
        \caption{Worldline of an instantaneous point-like source}
        \label{fig:inst_source}
    \end{minipage}
\end{figure}
\end{document}

enter image description here

1
  • This works perfectly. Thank you so much
    – mcp
    Oct 20, 2020 at 9:26
1

Just introduce \hspace{2pc} tag will add more horizontal space between the images, and the MWE is:

    \documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[a4paper,top=2.5cm,bottom=2.50cm,left=3.00cm,right=3.00cm]{geometry}


    \usepackage{float}
    \usepackage{wrapfig}
    \usepackage{amsmath,amssymb,commath}
    \usepackage{caption}    
    \usepackage{tikz}
    \usepackage[RPvoltages]{circuitikz}
    \usepackage{tkz-euclide}
    \usepackage{subcaption}
    

    \title{\Huge{\textbf{Test}}}
    \author{me}
    \date{}
    
    \begin{document}
    
    \maketitle
    
    \begin{figure}
        \begin{minipage}{0.4\textwidth}
            \centering
            \begin{tikzpicture}
                \centering
                \draw [<->,thick] (0,2.8) node (yaxis) [left] {$t$}
                    |- (2.8,0) node (xaxis) [right] {$x$};
                \draw[thick]
                    (0,0) -- (0,-2.8)
                    (0,0) -- (-2.8,0);
                \draw[green, ultra thick] (0,-2.90) -- (0,2.90);
                \draw[dashed] 
                    (0,2.90) -- (0,2.95)
                    (0,-2.90) -- (0,-2.95);
            \end{tikzpicture}
            \captionof{figure}{Worldline of a static point-like source}
            \label{fig:static_source}
        \end{minipage}\hspace{2pc}
        \begin{minipage}{0.4\textwidth}
            \centering
            \begin{tikzpicture}
                \draw [<->,thick] (0,2.8) node (yaxis) [left] {$t$}
                    |- (2.8,0) node (xaxis) [right] {$x$};
                \draw[thick]
                    (0,0) -- (0,-2.8)
                    (0,0) -- (-2.8,0);
                \node[mark size = 3pt, green] at (0,0) {\pgfuseplotmark{*}};
                \draw[dashed] 
                    (0,2.90) -- (0,2.95)
                    (0,-2.90) -- (0,-2.95);
            \end{tikzpicture}
            \captionof{figure}{Worldline of an instantaneous point-like source}
            \label{fig:inst_source}
        \end{minipage}
    \end{figure}
    
    \end{document}

OUTPUT

enter image description here Please correct me if my understanding is not correct....

3
  • 1
    The two caption remain overlapped. The problem is in the captionsetup. If you remove it, the two captions does not overlap anymore.
    – mcp
    Oct 19, 2020 at 14:27
  • @mcp Sorry, I couldn't see the overlap of caption, see my edit
    – MadyYuvi
    Oct 19, 2020 at 14:32
  • Your example works because you delete \captionsetup in OP MWE (and by this remove wrong caption's settings) and not because you introduce some space between minipages ...
    – Zarko
    Oct 19, 2020 at 15:15

You must log in to answer this question.

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