我试图在投影仪框架中并排添加两幅图像,但其中一幅超出了框架范围。
因此,我的其中一张图片是 pmatrix。我为邻接矩阵表示编写了以下代码:
\documentclass{article}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{graphicx}
\pagenumbering{gobble}
\begin{document}
\renewcommand\arraystretch{1}
\[\Huge{
\begin{pmatrix}
2 & 1 & 0 & 0 & 1 & 0 \\
1 & 0 & 1 & 0 & 1 & 0 \\
0 & 1 & 0 & 1 & 0 & 0 \\
0 & 0 & 1 & 0 & 1 & 1 \\
1 & 1 & 0 & 1 & 0 & 0 \\
0 & 0 & 0 & 1 & 0 & 0
\end{pmatrix}
}
\]
\vspace{15pt}
\huge{Adjacency Matrix (Coordinates are 1-6)}
\end{document}
我从 sharelatex 下载了 pdf 文件。但是当我添加它时,它超出了框架。这是我的 beamer 代码:
\documentclass[12pt]{beamer}
\usetheme{metropolis}
\usecolortheme{spruce}
\usepackage{mathtools}
\usepackage{amsmath}
\usepackage{fixmath}
\usepackage{graphicx}
\usepackage{svg}
\usepackage{multicol}
\setbeamercolor{background canvas}{bg = white}
\newcommand*{\Scale}[2][4]{\scalebox{#1}{$#2$}}%
\newcommand*{\Resize}[2]{\resizebox{#1}{!}{$#2$}}%
\DeclarePairedDelimiter\abs{\lvert}{\rvert}%
\DeclarePairedDelimiter\norm{\lVert}{\rVert}%
% Swap the definition of \abs* and \norm*, so that \abs
% and \norm resizes the size of the brackets, and the
% starred version does not.
\makeatletter
\let\oldabs\abs
\def\abs{\@ifstar{\oldabs}{\oldabs*}}
%
\let\oldnorm\norm
\def\norm{\@ifstar{\oldnorm}{\oldnorm*}}
\makeatother
\title[About Beamer]{Graph Representation Techniques}
\author[Author A and Author B]{Tanjim Bin Faruk (1505082) \\ Tanjim Munir (1505083) }
\institute{Bangladesh University of Engineering and Technology}
\date{\today}
\setbeamertemplate{title page}{
\begin{minipage}[b][\paperheight]{\textwidth}
\ifx\inserttitlegraphic\@empty\else\usebeamertemplate*{title graphic}\fi
\vfill%
\centering % NEW
\ifx\inserttitle\@empty\else\usebeamertemplate*{title}\fi
\ifx\insertsubtitle\@empty\else\usebeamertemplate*{subtitle}\fi
\usebeamertemplate*{title separator}
\vspace*{10mm}
\ifx\beamer@shortauthor\@empty\else\usebeamertemplate*{author}\fi
\vspace*{20mm} % NEW
\ifx\insertdate\@empty\else\usebeamertemplate*{date}\fi
\ifx\insertinstitute\@empty\else\usebeamertemplate*{institute}\fi
\vfill
\vspace*{1mm}
\end{minipage}
}
\setbeamertemplate{title}{
% \raggedright%
\centering
\linespread{1.0}%
\inserttitle%
\par%
\vspace*{0.5em}
}
\begin{document}
\metroset{block = fill}
\begin{frame}
\titlepage
\end{frame}
\begin{frame}[t]{Adjacency Matrix}
\vspace{1em}
\only<1>{
\begin{block}{What is an adjacency matrix?}
\vspace{0.5em}
An adjacency matrix is a square matrix used to represent a finite graph.
\end{block}
\vspace{0.5em}
For a graph with $\mathbold{\abs{V}}$ vertices, an adjacency matrix is a $\mathbold{\abs{V} \times \abs{V}}$ matrix.
\\\vspace{1em}
If the edge between vertex $\mathbold{i}$ and vertex $\mathbold{j}$ is denoted by $\mathbold{V_{i,j}}$ then there are two possibilities.
}
\only<2-3>{
\setbeamertemplate{itemize items}[ball]
\begin{enumerate}
\only<2>{
\item Unweighted Graph
\vspace{1em}
\begin{itemize}
\item Matrix of 0s and 1s where in row $\mathbold{i}$ and column $\mathbold{j}$ is $1$ iff the edge $\mathbold{(i,j)}$ is in the graph
\end{itemize}
\[ \Scale[1]{
V_{i,j} = \begin{cases}
1 & if ~ edge(i,j) ~ exists \\
0 & otherwise
\end{cases}
}
\]
}
\addtocounter{enumi}{1}
\only<3>{
\item Weighted Graph
\begin{itemize}
\item Edge weight is placed in $\mathbold{V_{i,j}}$ entry if there is an edge and a special value (perhaps \textit{\textbf{null}}) to indicate the absence of an edge.
\end{itemize}
\[
V_{i,j} = \begin{cases}
W_{i,j} & if ~ edge(i,j) ~ exists \\
null & otherwise
\end{cases}
\]
}
\end{enumerate}
}
\begin{multicols}{2}
\only<4>{
\begin{figure}
\centering
\includesvg[scale = 0.3]{Figures/unweightedgraph.svg}
\label{fig:my_label}
\end{figure}
\begin{figure}
\includegraphics[scale = 0.5]{Figures/temp.pdf}
\caption{Caption}
\label{fig:my_label}
\end{figure}
}
\end{multicols}
\end{frame}
\end{document}
我正在谈论我的代码的这个特定部分:
\begin{multicols}{2}
\only<4>{
\begin{figure}
\centering
\includesvg[scale = 0.3]{Figures/unweightedgraph.svg}
\label{fig:my_label}
\end{figure}
\begin{figure}
\includegraphics[scale = 0.5]{Figures/temp.pdf}
\caption{Caption}
\label{fig:my_label}
\end{figure}
}
\end{multicols}
当前输出如下所示:
我怎样才能解决这个问题?
答案1
您使用\Huge
和\huge
生成矩阵 PDF 图像,然后将其包含在内scale = 0.5
。为什么不直接pmatrix
在幻灯片中输入您的内容呢?
\begin{multicols}{2}
\only<4>{
\centering
\includesvg[scale = 0.3]{Figures/unweightedgraph.svg}
\[
\begin{pmatrix}
2 & 1 & 0 & 0 & 1 & 0 \\
1 & 0 & 1 & 0 & 1 & 0 \\
0 & 1 & 0 & 1 & 0 & 0 \\
0 & 0 & 1 & 0 & 1 & 1 \\
1 & 1 & 0 & 1 & 0 & 0 \\
0 & 0 & 0 & 1 & 0 & 0
\end{pmatrix}
\]
Adjacency Matrix (Coordinates are 1-6)
}
\end{multicols}
答案2
大部分与您的问题无关,但我无法再次展示如何准备这个框架并避免您的问题:
- 相反,我会使用 svg 图像来绘制自己的图像
tikz
(显示的图形相对简单,不需要花费很大的精力来编码) 我会编写矩阵而不是插入其图像(我确信,这更简单并且需要的工作更少)
\documentclass{beamer} \usetheme{metropolis} \usecolortheme{spruce} \usepackage{tikz} \usetikzlibrary{automata, positioning} \begin{document} \begin{frame}[t] \frametitle{Adjacency Matrix} \begin{columns} \begin{column}{.45\textwidth}\centering \begin{tikzpicture}[ every node/.style = {circle, draw=blue!70!black, fill=cyan!30}, node distance = 3mm and 5mm, thick ] \node (s1) {1}; \node (s2) [above left=of s1] {2}; \node (s3) [above=of s2] {3}; \node (s4) [right=of s3] {4}; \node (s5) [above right=of s1] {5}; \node (s6) [above right=of s4] {6}; \draw (s1) to [loop right, looseness=12] (s1) (s1) -- (s2) -- (s3) -- (s4) -- (s5) -- (s1) (s2) -- (s5) (s4) -- (s6); \end{tikzpicture} \end{column} \begin{column}{.45\textwidth} \[\setlength\arraycolsep{9pt} \begin{pmatrix} 2 & 1 & 0 & 0 & 1 & 0 \\ 1 & 0 & 1 & 0 & 1 & 0 \\ 0 & 1 & 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 & 1 & 1 \\ 1 & 1 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 \end{pmatrix} \] \end{column} \end{columns} \end{frame} \end{document}
答案3
我不会
multicols
与 beamer 一起使用 - beamer 有自己的柱子机制。你不需要
\usepackage{graphicx}
使用 beamer就我个人而言,我发现仅指定图像的宽度要容易得多,而不必试验寻找合适的缩放因子。
不要多次使用相同的标签
图形在投影机中自动居中,无需
\centering
% !TeX program = txs:///arara
% arara: pdflatex: {synctex: on, interaction: nonstopmode, shell: yes}
\documentclass[12pt]{beamer}
\usetheme{moloch}% modern fork of the metropolis theme
\usecolortheme{spruce}
%\usepackage{graphicx}
\usepackage{svg}
\begin{document}
\begin{frame}[t]{Adjacency Matrix}
\begin{columns}[onlytextwidth]
\begin{column}{.3\textwidth}
\begin{figure}
\includesvg[width=\textwidth]{unweightedgraph.svg}
\label{fig:my_label}
\end{figure}
\end{column}
\begin{column}{.45\textwidth}
\begin{figure}
\includegraphics[width=\textwidth]{example-image}
\label{fig:my_labela}
\end{figure}
\end{column}
\end{columns}
\end{frame}
\end{document}