
저는 Markdown에서 LaTeX 또는 Beamer로 변환하기 위해 Pandoc을 사용하고 있습니다. Pandoc의 LaTeX 템플릿에는 텍스트 너비에 맞게 이미지 크기가 조정되지만 Beamer 출력은 그렇지 않은 멋진 명령이 있습니다.
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth
\else\Gin@nat@width\fi}
\makeatother
\let\Oldincludegraphics\includegraphics
\renewcommand{\includegraphics}[1]{\Oldincludegraphics[width=\maxwidth]{#1}}
그래서 Beamer 템플릿에 명령을 복사하려고 시도했지만 pdflatex로 컴파일하는 동안 오류가 발생합니다. 서문을 확인했지만 어느 것이 호환되지 않는지 알 수 없습니다. 어쩌면 비머 클래스 자체가 문제일까요?
여기 내 샘플 비머 코드가 있습니다.
\documentclass[ignorenonframetext,]{beamer}
\usepackage{amssymb,amsmath}
\usepackage{ifxetex,ifluatex}
\usepackage{fixltx2e} % provides \textsubscript
\ifxetex
\usepackage{fontspec,xltxtra,xunicode}
\defaultfontfeatures{Mapping=tex-text,Scale=MatchLowercase}
\else
\ifluatex
\usepackage{fontspec}
\defaultfontfeatures{Mapping=tex-text,Scale=MatchLowercase}
\else
\usepackage[utf8]{inputenc}
\fi
\fi
\usepackage{graphicx}
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth
\else\Gin@nat@width\fi}
\makeatother
\let\Oldincludegraphics\includegraphics
\renewcommand{\includegraphics}[1]{\Oldincludegraphics[width=\maxwidth]{#1}}
% Comment these out if you don't want a slide with just the
% part/section/subsection/subsubsection title:
\AtBeginPart{\frame{\partpage}}
\AtBeginSection{\frame{\sectionpage}}
\AtBeginSubsection{\frame{\subsectionpage}}
\AtBeginSubsubsection{\frame{\subsubsectionpage}}
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}
\setlength{\emergencystretch}{3em} % prevent overfull lines
\setcounter{secnumdepth}{0}
\begin{document}
\begin{frame}\frametitle{Introduction}
Testing image size from R saved by various methods.
\end{frame}
\begin{frame}\frametitle{Results}
All images were set width = 7. For ggsave, the dpi =300.
\begin{block}{Saved by ggsave}
\begin{figure}[htbp]
\centering
\includegraphics{./plot_by_ggsave.pdf}
\caption{Saved by ggsave}
\end{figure}
\end{block}
\end{frame}
\end{document}
답변1
클래스 beamer
는 재정의 \includegraphics
하지만 "문서 시작 시"이므로 재정의도 동시에 제공되어야 합니다.
\usepackage{letltxmacro}
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
\makeatother
\AtBeginDocument{
\LetLtxMacro\Oldincludegraphics\includegraphics
\renewcommand{\includegraphics}[2][]{%
\Oldincludegraphics[#1,width=\maxwidth]{#2}}
}
왜 필요한지 letltxmacro
이해하려면 설명서를 참조하세요 .\LetLtxMacro