我的 Beamer 演示文稿出现问题,我想在一张幻灯片中插入 2 个 Tikz 子图。为此,我使用了调整框,但出现了错误。
当我单独放置每个 tikzpicture 时没有错误,但是,当我尝试将它们放入 2 个子图时出现错误。
我一直在研究相关问题的答案。问题似乎与图形环境中的子浮点数有关,但我没有满意的答案。
我的代码:
\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}
谢谢你!
答案1
离题了,但很重要:
- 在其他软件包之间,beamer 也加载了
graphicx
,hyperref
因此再次加载它们是多余的 - beamer 有自己的列表 (
itemize
,enumerate
) 适用于其特定。因此使用任何其他包关注列表可能会很脆弱
您的问题似乎是由adjustbox
(和使用过时的subfigure
包)引起的。我建议使用adjustwidth
包中的宏changepage
。在下面的 MWE 中,我删除了 MWE 中的所有杂乱内容(未使用的代码片段),因此代码现在非常简洁。我还替换了过时的subfigure package with
子标题`。
\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}
我希望图像接近您想要的效果:)