0

I'm having problems with my beamer presentation, I would like to insert 2 Tikz subfigures into only one slide. For that I'm using an adjustbox but I'm having errors.

When I put each tikzpicture separately there is no error, notwithstanding, when I try to get them into 2 subfigures the error comes out.

I've looking into answers to related problems. It looks that the problem is related to subfloats into the figure environment but I've no satisfactory answer.

My code:

\documentclass[serif, xcolor={usenames,dvipsnames,table}]{beamer}
 \usepackage[portuguese]{babel}
 \usepackage[utf8]{inputenc}
 \usepackage{mathpazo}
 \let\Tiny=\tiny

 \mode<presentation> {
 \usetheme{Malmoe}
 \usecolortheme{beaver}
 }
 \usepackage{graphicx}
 \usepackage{subfigure}
 \usepackage{amssymb}
 \usepackage{mathtools}
 \usepackage{enumerate}

 \setbeamertemplate{section in head/foot}{\hfill\insertsectionhead}
 \setbeamertemplate{section in head/foot shaded}{\color{red!40}\hfill\insertsectionhead}
 \setbeamertemplate{section in toc}{\inserttocsectionnumber.~\inserttocsection}
 \usepackage{hyperref}
 \usepackage[alf]{abntex2cite}
 \usepackage{tikz}
 \usetikzlibrary{arrows}
 \newcommand*\circled[1]{\tikz[baseline=(char.base)]{\node[shape=circle,draw,inner sep=2pt] (char) {#1};}}   %texto circulado

 \usepackage{adjustbox}
 \usepackage{booktabs}
 \usepackage{multirow}
 \usepackage{multicol}
%------------------------------------------------

\begin{document}
\begin{frame}{Eliminação de \textit{subtour}}
\begin{adjustbox}{max totalsize={1\textwidth}{.9\textheight},center}
    \begin{figure}[htpb]
    \centering
    \subfigure[Eliminado pela variável $ \gamma $ e os conjuntos $ \Xi $]{
        \begin{tikzpicture}[->, >=stealth', shorten >=1pt, auto, node distance=3cm, thick, main node/.style={circle, draw, font=\sffamily}]
        \node[main node, label={above:Q1}] (1) {a};
        \node[main node, label={above:R1}] (2) [right of=1] {c};
        \node[main node, label={above:Q2}] (3) [right of=2] {d};
        \node[main node, label={above:S2}] (4) [right of=3] {b};
        \node[](aux1) at (5,-0.5) {};
        \node[main node, label={left:P1}] (5) [below of=aux1] {g};  
        \node[](aux2) [below left of=1] {};
        \node[main node, label={right:P3}] (6) [above right of=5] {e};  
        \node[main node, label={right:P2}] (7) [below right of=5] {f};
        \path[every node/.style={font=\sffamily\small}]
        (1) edge [right] node[left, below] {} (2)
        (2) edge [right] node[left, below] {} (3)
        (3) edge [right] node[left, below] {} (4)
        (5) edge [right] node[left]             {} (7)
        (7) edge [right] node[right]            {} (6)
        (6) edge [red, right, line width=1.8pt] node[left, red]     {} (5); 
        \end{tikzpicture}}
    \subfigure[Eliminado pelas restrições \eqref{eq:sd-subtour-lmo}]{   
        \begin{tikzpicture}[->, >=stealth', shorten >=1pt, auto, node distance=3cm, thick, main node/.style={circle, draw, font=\sffamily}]
        \node[main node, label={above:Q1}] (1) {a};
        \node[main node, label={above:R2}] (2) [right of=1] {c};
        \node[main node, label={above:Q2}] (3) [right of=2] {d};
        \node[main node, label={above:S2}] (4) [right of=3] {b};
        \node[](aux1) at (3,-0.5) {};
        \node[main node, label={left:R1}] (5) [below of=aux1] {g};  
        \node[](aux2) [left of=5] {};
        \node[main node, label={right:P3}] (6) [above right of=5] {e};  
        \node[main node, label={right:P2}] (7) [below right of=5] {f};
        \path[every node/.style={font=\sffamily\small}]  
        (1) edge [right] node[left, below] {} (2)
        (2) edge [right] node[left, below] {} (3)
        (3) edge [right] node[left, below] {} (4)
        (5) edge [right] node[left] {} (7)
        (7) edge [right] node[right] {} (6)
        (6) edge [right] node[left, red] {} (5);    
        \end{tikzpicture}}
 \end{figure}
 \end{adjustbox}
 \end{frame}
\end{document}

Thank you!

2
  • your problem is missing curly braces in \setbeamertemplate{section in head/foot shaded}\color{red!40}\hfill\insertsectionhead} \setbeamertemplate{section in toc}\inserttocsectionnumber.~\inserttocsection} correct is \setbeamertemplate{section in head/foot shaded}{\color{red!40}\hfill\insertsectionhead} \setbeamertemplate{section in toc}{\inserttocsectionnumber.~\inserttocsection} – Zarko Apr 24 '17 at 22:55
  • Hi Zarko, editing the code I forgot the braces here, but the error is there yet. Error: Something's wrong--perhaps a missing \item. \end{frame} – Víctor Mario Noble Ramos Apr 24 '17 at 23:03
2

Off-topic, but important:

  • between other packages beamer also load graphicx and hyperref , so it is surplus to load them again
  • beamer has own list (itemize, enumerate) adopted to its specific. consequently use any other packages concerns list can be fragile

Your problem seems to be caused by adjustbox (and use of obsolete subfigure package). Instead of it I suggest to use macro adjustwidth from package changepage. In MWE below I remove all clutter in your MWE (not used fragments of code), so the code is now very concise. Also I replace obsolete subfigure package withsubcaption`.

\documentclass[serif, xcolor={usenames,dvipsnames,table}]{beamer}
 \usepackage[portuguese]{babel}
 \usepackage[utf8]{inputenc}
 \usepackage{mathpazo}
 \let\Tiny=\tiny

 \mode<presentation> {
 \usetheme{Malmoe}
 \usecolortheme{beaver}
 }
 %\usepackage{graphicx} not needed
 \usepackage{subcaption}
 \usepackage{amssymb, mathtools}
 %\usepackage{enumerate}

 \setbeamertemplate{section in head/foot}{\hfill\insertsectionhead}
 \setbeamertemplate{section in head/foot shaded}{\color{red!40}\hfill\insertsectionhead}
 \setbeamertemplate{section in toc}{\inserttocsectionnumber.~\inserttocsection}
 %\usepackage{hyperref}
 \usepackage[alf]{abntex2cite}

 \usepackage{tikz}
 \usetikzlibrary{arrows.meta, chains, positioning}
 \newcommand*\circled[1]{\tikz[baseline=(char.base)]{\node[shape=circle,draw,inner sep=2pt] (char) {#1};}}   %texto circulado
\makeatletter
\tikzset{join reset/.code={\def\tikz@after@path{}}}
\makeatother

 %\usepackage{adjustbox} better not use it
 \usepackage{booktabs, multirow}
 %\usepackage{multicol} not needed, beamer has own
 \usepackage{changepage} % for more space fo image
%------------------------------------------------

\begin{document}
\begin{frame}
\frametitle{Eliminação de \textit{subtour}}
    \begin{figure}
\tikzset{
shorten >=1pt,
        node distance = 9mm and 5mm,
          start chain = going right,
            MN/.style = {% Main Node
                        circle, draw, semithick, font=\sffamily\scriptsize,
                        minimum size=3ex, inner sep=2pt,
                        on chain, join=by -{Straight Barb[]}},
    }
\begin{adjustwidth}{-6mm}{-6mm}
\centering
        \begin{subfigure}[t]{0.48\linewidth}
        \begin{tikzpicture} 
    \node[MN, label=Q1] (1) {a};
    \node[MN, label=R2] (2) {c};
    \node[MN, label=Q2] (3) {d};
    \node[MN, label=S2] (4) {b};
%
    \node[MN, join reset,
          label=left:P1,
          below=of 4] (5) {g};
    \node[MN, label=right:P3,
          above right=of 5.south] (6) {e};
    \node[MN, label=right:P2,
          below right=of 5.north] (7) {f};
    \draw[-{Straight Barb[]}]  (7) -- (5);
    \draw[red, line width=1pt,-{Straight Barb[]}]  (5) -- (6);
        \end{tikzpicture}
    \caption{Eliminado pela variável $ \gamma $ e os conjuntos $ \Xi $}
    \end{subfigure}
\hfill        
    \begin{subfigure}[t]{0.48\linewidth}
        \begin{tikzpicture}
    \node[MN, label=Q1] (1) {a};
    \node[MN, label=R2] (2) {c};
    \node[MN, label=Q2] (3) {d};
    \node[MN, label=S2] (4) {b};
%
    \node[MN, join reset,
          label=left:P1,
          below=of 4] (5) {g};
    \node[MN, label=right:R1,
          above right=of 5.south] (6) {e};
    \node[MN, label=right:P2,
          below right=of 5.north] (7) {f};
    \draw[-{Straight Barb[]}]  (7) -- (5);
        \end{tikzpicture}
    \caption{Eliminado pelas restrições \eqref{eq:sd-subtour-lmo}}
     \end{subfigure}
    \end{adjustwidth}
    \end{figure}
\end{frame}
\end{document}

enter image description here

I hope that the image is close to what you like to have :)

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.