4

I failed to center all captions in each subfigure like thisenter image description here. Captions in the left part (four subfigures "A") are not at the center I think. Captions in the right part (four dependencies) are aligned on the left and the line width of the caption does not work properly as well. Can anyone help me with this problem? I just want to center each caption.

\documentclass[11pt,a4paper]{article}
\usepackage{bbm}
\usepackage{times}
\usepackage{latexsym}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{url}
\usepackage{mathtools}
\usepackage{verbatim}
\usepackage[utf8]{inputenc}
\usepackage[shellescape]{gmp}
\usepackage{dot2texi}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\usepackage{natbib}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{tikz-dependency}
\usepackage{wrapfig}
\usepackage{multirow}
\usepackage{pgfplots}
\usepackage{filecontents}
\usepackage[T1]{fontenc}
\usepackage{subfiles}
\usepackage{readarray}
\usepackage{xcolor}
\usepackage{import}
\usepackage{tikz}
\usepackage{tikz-dependency}
\usetikzlibrary{matrix,positioning}
\usetikzlibrary{automata,arrows}
%\usepackage{ifthen}
%\usepackage{subfiles}
%\subfile{graphs/q_value.tex}
\usetikzlibrary{calc}
\begin{document}
\tikzstyle{line}=[bend right=30,thin]
\pgfmathsetmacro\myscale{0.95}
\begin{figure*}
\centering
%\begin{minipage}{0.48\linewidth}
%The first part of subfigure
\begin{minipage}[h]{.60\textwidth}
\begin{subfigure}[t]{0.475\textwidth}
\centering
\includegraphics[scale=.45]{example-image-a}

\caption*{(1) 1st iteration}
\end{subfigure}
\hfill
\begin{subfigure}[t]{0.475\textwidth}
\centering
\includegraphics[scale=.45]{example-image-a}
\caption*{(2) 2nd iteration}
\end{subfigure}
\begin{subfigure}[t]{0.475\textwidth}
\centering
\includegraphics[scale=.45]{example-image-a}
\caption*{(3) 3rd iteration}
\end{subfigure}
\hfill
\begin{subfigure}[t]{0.475\textwidth}
\centering
\includegraphics[scale=.45]{example-image-a}
\caption*{(4) Final prediction}
\end{subfigure}
\end{minipage}
\hfill
\begin{minipage}[h]{.30\textwidth}
\begin{subfigure}[t]{0.475\textwidth}
\centering
\begin{dependency}[theme = simple]
\begin{deptext}[column sep=0.3cm, font=\normalsize]
They \& were \& not \& Poles \\
\end{deptext}
%add----
\deproot[thick,dotted,edge height=30pt]{2}{\normalsize <ROOT>}
\deproot[red, edge height=30pt]{4}{\normalsize <ROOT>}
%\depedge[]{1}{2}{}
\depedge[thick,dotted]{2}{1}{}
\depedge[thick,dotted]{2}{3}{}
\depedge[]{2}{4}{}
\end{dependency}
\caption*{(1) 1st iteration}
\end{subfigure}

\begin{subfigure}[t]{0.475\textwidth}
\centering
\begin{dependency}[theme = simple]
\begin{deptext}[column sep=0.3cm, font=\normalsize]
They \& were \& not \& Poles \\
\end{deptext}
%add----
\deproot[thick,dotted,edge height=30pt]{2}{\normalsize <ROOT>}
%\deproot[edge height=30pt]{3}{\normalsize ROOT}
%\depedge[]{1}{2}{}
\depedge[thick,dotted]{2}{1}{}
\depedge[thick,dotted]{2}{3}{}
\depedge[thick,dotted]{2}{4}{}
\end{dependency}
\caption*{(2) 2nd iteration}
\end{subfigure}

\begin{subfigure}[t]{0.475\textwidth}
\centering
\begin{dependency}[theme = simple]
\begin{deptext}[column sep=0.3cm, font=\normalsize]
They \& were \& not \& Poles \\
\end{deptext}
%add----
\deproot[edge height=30pt]{2}{\normalsize <ROOT>}
%\deproot[edge height=30pt]{3}{\normalsize ROOT}
%\depedge[]{1}{2}{}
\depedge[thick,dotted]{2}{1}{}
\depedge[thick,dotted]{2}{3}{}
\depedge[]{2}{4}{}
\end{dependency}
\caption*{(3) 3rd iteration}
\end{subfigure}


\begin{subfigure}[t]{0.475\textwidth}
\centering
\begin{dependency}[theme = simple]
\begin{deptext}[column sep=0.3cm, font=\normalsize]
They \& were \& not \& Poles \\
\end{deptext}
%add----
\deproot[edge height=30pt]{2}{\normalsize <ROOT>}
%\deproot[edge height=30pt]{3}{\normalsize ROOT}
%\depedge[]{1}{2}{}
\depedge[]{2}{1}{}
\depedge[]{2}{3}{}
\depedge[]{2}{4}{}
\end{dependency}
\caption*{(4) Final prediction}
\end{subfigure}

\end{minipage}

%\end{minipage}
%End of The first part of subfigure
%The second part of subfigure
%PSD ood test set
\caption{}
    \label{fig:example}
\end{figure*}

\end{document}
  • 1
    Instead of \includegraphics[scale=.45]{...}, write \includegraphics[width=\textwidth]{...}. – Mico May 15 at 6:49
  • Please also tell us how the dependency and deptext environments and the \deproot and \depedge macros are defined. – Mico May 15 at 7:01
  • I update the code, it can be compiled now. – oriuta May 15 at 10:36
4

You need to make two main adjustments:

  • In the left-hand minipage, replace all instances of [scale=.45] with either [width=\textwidth] or [width=\textwidth,height=\textwidth].

  • In the right-hand minipage, replace all instances of \begin{subfigure}[t]{0.475\textwidth} with \begin{subfigure}[t]{1\textwidth}.

Two additional comments: (a) Don't load the obsolete and unmaintained latexsym package. Instead, load the amssmyb package. (b) Don't load packages more than once -- nothing good will come out of it.

enter image description here

\documentclass[11pt,a4paper]{article}
\usepackage{bbm}
\usepackage{times}
%%%%\usepackage{latexsym}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{amssymb}%%%{amsfonts}
\usepackage{url}
\usepackage{mathtools}
\usepackage{verbatim}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage[shellescape]{gmp}
\usepackage{dot2texi}

\usepackage{natbib}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{wrapfig}
\usepackage{multirow}
\usepackage{pgfplots}
\usepackage{filecontents}
\usepackage{subfiles}
\usepackage{readarray}
\usepackage{xcolor}
\usepackage{import}

\usepackage{tikz}
%%%%\usepackage{tikz}
\usepackage{tikz-dependency}
%%%%\usepackage{tikz-dependency}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{matrix,positioning}
\usetikzlibrary{automata,arrows}
\usetikzlibrary{calc}

%\usepackage{ifthen}
%\usepackage{subfiles}
%\subfile{graphs/q_value.tex}

\begin{document}
\tikzstyle{line}=[bend right=30,thin]
\pgfmathsetmacro\myscale{0.95}

\begin{figure}
%\centering
%The first part of figure
\begin{minipage}[]{.60\textwidth}
\begin{subfigure}[]{0.475\textwidth}
%%%\centering
\includegraphics[width=\textwidth,height=\textwidth]{example-image-a}
\caption*{(1) 1st iteration}
\end{subfigure}%
%%%
\hfill
\begin{subfigure}[]{0.475\textwidth}
%%%\centering
\includegraphics[width=\textwidth,height=\textwidth]{example-image-a}
\caption*{(2) 2nd iteration}
\end{subfigure}

\bigskip
\begin{subfigure}[]{0.475\textwidth}
%%%\centering
\includegraphics[width=\textwidth,height=\textwidth]{example-image-a}
\caption*{(3) 3rd iteration}
\end{subfigure}%
%%%
\hfill
\begin{subfigure}[]{0.475\textwidth}
%%%\centering
\includegraphics[width=\textwidth,height=\textwidth]{example-image-a}
\caption*{(4) Final prediction}
\end{subfigure}
\end{minipage}%
%%%%%%
\hfill
\begin{minipage}[]{.38\textwidth} %Second part of figure
\begin{subfigure}[]{\textwidth}
\centering
\begin{dependency}[theme = simple]
\begin{deptext}[column sep=3mm, font=\normalsize]
They \& were \& not \& Poles \\
\end{deptext}
\deproot[thick,dotted,edge height=30pt]{2}{\normalsize <ROOT>}
\deproot[red, edge height=30pt]{4}{\normalsize <ROOT>}
%\depedge[]{1}{2}{}
\depedge[thick,dotted]{2}{1}{}
\depedge[thick,dotted]{2}{3}{}
\depedge[]{2}{4}{}
\end{dependency}
\caption*{(1) 1st iteration}
\end{subfigure}

\medskip
\begin{subfigure}[]{\textwidth}
\centering
\begin{dependency}[theme = simple]
\begin{deptext}[column sep=0.3cm, font=\normalsize]
They \& were \& not \& Poles \\
\end{deptext}
\deproot[thick,dotted,edge height=30pt]{2}{\normalsize <ROOT>}
%\deproot[edge height=30pt]{3}{\normalsize ROOT}
%\depedge[]{1}{2}{}
\depedge[thick,dotted]{2}{1}{}
\depedge[thick,dotted]{2}{3}{}
\depedge[thick,dotted]{2}{4}{}
\end{dependency}
\caption*{(2) 2nd iteration}
\end{subfigure}

\medskip
\begin{subfigure}[]{\textwidth}
\centering
\begin{dependency}[theme = simple]
\begin{deptext}[column sep=0.3cm, font=\normalsize]
They \& were \& not \& Poles \\
\end{deptext}
\deproot[edge height=30pt]{2}{\normalsize <ROOT>}
%\deproot[edge height=30pt]{3}{\normalsize ROOT}
%\depedge[]{1}{2}{}
\depedge[thick,dotted]{2}{1}{}
\depedge[thick,dotted]{2}{3}{}
\depedge[]{2}{4}{}
\end{dependency}
\caption*{(3) 3rd iteration}
\end{subfigure}

\medskip
\begin{subfigure}[]{\textwidth}
\centering
\begin{dependency}[theme = simple]
\begin{deptext}[column sep=0.3cm, font=\normalsize]
They \& were \& not \& Poles \\
\end{deptext}
\deproot[edge height=30pt]{2}{\normalsize <ROOT>}
%\deproot[edge height=30pt]{3}{\normalsize ROOT}
%\depedge[]{1}{2}{}
\depedge[]{2}{1}{}
\depedge[]{2}{3}{}
\depedge[]{2}{4}{}
\end{dependency}
\caption*{(4) Final prediction}
\end{subfigure}
\end{minipage}


\caption{}
    \label{fig:example}
\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.