假设我正在准备课程介绍幻灯片,并希望在参考书目中的每个条目中添加一张图片。(这有两个目的,名称会留在学生的脑海中,这将使演示不至于无聊,特别是在我的第一节课上。)
到目前为止,我已经手动完成了这项工作(在适当的位置复制粘贴预先生成的参考书目)。
\documentclass{beamer}
\usepackage{graphicx}
\begin{document}
\begin{frame}
\frametitle{References}
\begin{columns}
\begin{column}{0.4\textwidth}
\begin{center}
\includegraphics[width=\textwidth]{figures/lamport}
\end{center}
\end{column}
\begin{column}{0.7\textwidth}
\begin{itemize}
\item L.~Lamport, {\em LaTeX - {A} Document Preparation System:
User's Guide and Reference Manual, Second Edition}. Pearson
/ Prentice Hall, 1994.
\end{itemize}
\end{column}
\end{columns}
\end{frame}
\end{document}
输出效果相当不错。
但我想摆脱手动部分(这相当繁琐且容易出错,并且可扩展性不强)并且想知道是否可以自动完成这一部分。
到目前为止,我一直尝试使用note
.bib 条目字段。
\documentclass{beamer}
\bibliographystyle{ieeetr}
\def\bibimage#1#2{\includegraphics[#1]{figures/#2}}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@book{DBLP:books/daglib/0023602,
author = {Leslie Lamport},
title = {LaTeX - {A} Document Preparation System: User's Guide and Reference
Manual, Second Edition},
year = {1994},
publisher = {Pearson / Prentice Hall},
note = {\bibimage{width=0.25\textwidth}{lamport}}}
\end{filecontents}
\usepackage{graphicx}
\begin{document}
\nocite{DBLP:books/daglib/0023602}
\begin{frame}
\frametitle{Text Books and Other Resources}
\bibliography{\jobname}
\end{frame}
\end{document}
但是我无法控制图片的位置。正如您在本文开头看到的,我的设想是将每条条目的文本放在左侧或右侧,并将相应的图片以平衡的方式放在另一侧。
答案1
它很容易出错,但我不确定破解它.bst
是否可行:对于非常专业的用途来说,这似乎需要做很多工作。我可能会用类似以下方法简化您的方法:
\newcommand{\picnbib}[2]{%
% #1 = picture call ; #2 the bibliography reference (NB: I used biblatex)
\begin{columns}
\begin{column}{0.4\textwidth}
\begin{center}
\includegraphics[width=\textwidth]{#1}%
\end{center}
\end{column}
\begin{column}{0.7\textwidth}
\begin{itemize}
\item \fullcite{#2}
\end{itemize}
\end{column}
\end{columns}
}
因此,综合起来:
\documentclass{beamer}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@book{lamport1994,
author = {Leslie Lamport},
title = {LaTeX - {A} Document Preparation System: User's Guide and Reference
Manual, Second Edition},
year = {1994},
publisher = {Pearson / Prentice Hall},
location = {Wherever},
}
\end{filecontents}
% note = {\bibimage{width=0.25\textwidth}{lamport}}
\usepackage{graphicx}
\usepackage[style=authortitle]{biblatex}
\addbibresource{\jobname.bib}
\newcommand{\picnbib}[2]{%
\begin{columns}
\begin{column}{0.4\textwidth}
\begin{center}
\includegraphics[width=\textwidth]{#1}
\end{center}
\end{column}
\begin{column}{0.7\textwidth}
\begin{itemize}
\item \fullcite{#2}
\end{itemize}
\end{column}
\end{columns}
}
\begin{document}
\begin{frame}
\frametitle{References}
\picnbib{figures/lamport}{lamport1994}
\end{frame}
\end{document}
您可能需要调整上述宽度;我将其保留为您的示例不变。
编辑 如果你不能使用biblatex
,事情会变得更加困难和脆弱。但这里有一个依赖于的想法usebib
:
\documentclass{beamer}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@book{lamport1994,
author = {Leslie Lamport},
title = {LaTeX - {A} Document Preparation System: User's Guide and Reference
Manual, Second Edition},
year = {1994},
publisher = {Pearson / Prentice Hall},
location = {Wherever},
picture = {\includegraphics[width=0.5\textwidth]{000.jpg}},% <-- change the image file!
}
\end{filecontents}
% note = {\bibimage{width=0.25\textwidth}{lamport}}
\usepackage{graphicx}
\usepackage{natbib}
\usepackage{usebib}
\newbibfield{author}
\newbibfield{picture}
\newbibfield{publisher}
\bibinput{\jobname}
\newcommand{\picnbib}[1]{%
\begin{columns}
\begin{column}{0.4\textwidth}
\begin{flushright}
% \includegraphics[width=0.5\textwidth]{#1}
\usebibentry{#1}{picture}
\end{flushright}
\end{column}
\begin{column}{0.7\textwidth}
\begin{itemize}
\item \printbibentry{#1}%
\end{itemize}
\end{column}
\end{columns}
}
\newcommand{\printbibentry}[1]{%
\usebibentry{#1}{author},
{\itshape \usebibentry{#1}{title}}
(\usebibentry{#1}{publisher}, \usebibentry{#1}{year})
}
\begin{document}
\begin{frame}
%\printbibentry{lamport1994}
\frametitle{References}
\picnbib{lamport1994}
\end{frame}
\bibliographystyle{plain}
\bibliography{\jobname}
\end{document}
需要注意的是,您需要\picnbib
为每种不同的条目类型创建命令变体。此外,通过将图片硬编码到文件中bib
,您可能需要非常小心\includegraphics
每个条目中执行的操作。
答案2
另一种方法是嗜酒代替 BibTeX 或 Biblatex,值得注意的是,它的实现非常简单。使用bib
下面的示例数据库文件
@Book{Lamport-1994,
author = {Leslie Lamport},
title = {LaTeX: A Document Preparation System: User's Guide and Reference Manual},
edition = {2},
year = {1994},
image_filename = {lamport_image},
publisher = {Pearson / Prentice Hall}
}
@Book{Knuth-1984,
title = {TeXbook},
year = {1984},
author = {Donald Knuth},
image_filename = {knuth_image},
publisher = {Addison-Wesley}
}
@Book{Gratzer-2007,
title = {More Math into LaTeX},
year = {2007},
author = {George Gr{\"a}tzer},
edition = {4},
image_filename = {gratzer_image},
publisher = {Springer}
}
我们可以创建一个模板,用于在每个书目条目前面插入图像,如下所示。(请注意,数据库文件仅包含书籍,因此此处定义的唯一模板是书籍条目的模板。)
TEMPLATES:
book = \begin{minipage}{\linewidth}...
\begin{minipage}{\makeopenbracket}c{\makeclosebracket}{0.15\linewidth}...
\includegraphics{\makeopenbracket}width=\linewidth{\makeclosebracket}{<image_filename>}...
\end{minipage}...
\hfill...
\begin{minipage}{\makeopenbracket}c{\makeclosebracket}{0.8\linewidth}...
<au>, \textit{<title>}[, <edition.ordinal()> Edition]. <publisher>, <year>. ...
\end{minipage}...
\end{minipage}
该模板创建了一对小页面——一个用于插入图像,另一个用于插入相应的文本,因此两个页面彼此居中。文本的格式与 OP 的示例非常接近。
将此模板文件与上述数据库一起使用,在主文件上运行 PDFTeX
\documentclass{article}
\usepackage[pdftex]{graphicx}
\usepackage[paper=letterpaper, text={4in,5in},centering]{geometry}
\makeatletter
\renewcommand{\@biblabel}[1]{}
\newcommand{\citenum}[1]{\def\@cite##1##2{##1}\cite{#1}}
\makeatother
\begin{document}
References \citenum{Knuth-1984}, \citenum{Lamport-1994}, and \citenum{Gratzer-2007} are useful for learning {\TeX} and \LaTeX.
\bibliography{example10}
\bibliographystyle{example10}
\end{document}
产生如下所示的输出
答案3
(这个答案实际上是这个答案,我已经接受了。我仍然发布此内容,希望扩展版本可能对某些人有用。此答案允许您创建一个样式文件,,picinbib.sty
其中包含一些可能用到的可选开关。)
解决方案代码
\documentclass{beamer}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@BOOK{Lamport199407,
title={LaTeX: A Document Preparation System},
author={Leslie Lamport},
publisher={Addison-Wesley Professional},
year={1994},
month=jul,
edition={2nd}
}
\end{filecontents}
\begin{filecontents}{picinbib.sty}
% Adapted from https://tex.stackexchange.com/a/207763/14103
% Usage is \picinbib[L|R]{imagefile}{reference key}
\ProvidesPackage{picinbib}
\RequirePackage{graphicx}
\RequirePackage{biblatex}
\RequirePackage{xstring}
\newcommand{\picinbib}[3][L]{%
\def\@side{L}%
\IfEqCase{#1}{%
{L}{\relax}%
{R}{\def\@side{R}}%
}[\PackageWarning{picinbib}{Undefined option: #1}]
\csname picinbib@\@side\endcsname{#2}{#3}}
\def\@reference@content#1{%
\begin{column}{0.80\textwidth}%
\begin{itemize}%
\item\fullcite{#1}%
\end{itemize}%
\end{column}%
}
\def\@referene@picture#1{%
\begin{column}{0.20\textwidth}%
\begin{center}%
\includegraphics[width=\textwidth]{#1}%
\end{center}%
\end{column}%
}
% Image at left
\def\picinbib@L#1#2{%
\begin{columns}
\@referene@picture{#1}
\@reference@content{#2}
\end{columns}
}
% Image at right
\def\picinbib@R#1#2{%
\begin{columns}
\@reference@content{#2}
\@referene@picture{#1}
\end{columns}
}
\endinput
\end{filecontents}
\usepackage{picinbib}
\addbibresource{\jobname.bib}
\begin{document}
\begin{frame}
\picinbib{lamportcover}{Lamport199407}
\picinbib[R]{lamportcover}{Lamport199407}
\picinbib[L]{lamportcover}{Lamport199407}
\picinbib[X]{lamportcover}{Lamport199407}
\end{frame}
\end{document}
上述代码的用法
- 将完整的代码保存在文件中,例如
mybibpic.tex
。 - 节省此图像文件位于同一目录中,名称为
lamportcover.png
。
现在执行以下命令,
pdflatex mybibpic biber mybibpic pdflatex mybibpic pdflatex mybibpic
picinbib.sty
以上生成可用于其他项目的文件。(并且肯定会生成mybibpic.pdf
显示结果的文件。)
用于其他项目
将(在上一节中生成)复制picinbib.sty
到 LaTeX 可以找到的某个位置。
上述样式文件提供的命令是,
\picinbib[L|R]{imagefile}{bibliography reference key}
确定L|R
图像位置,左侧或右侧。默认在左侧。