惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
Visual Studio Blog
爱范儿
爱范儿
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
雷峰网
雷峰网
V
V2EX
博客园_首页
Engineering at Meta
Engineering at Meta
博客园 - 聂微东
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Apple Machine Learning Research
Apple Machine Learning Research
GbyAI
GbyAI
H
Help Net Security
A
About on SuperTechFans
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Blog — PlanetScale
Blog — PlanetScale
W
WeLiveSecurity
云风的 BLOG
云风的 BLOG
D
Docker
Security Archives - TechRepublic
Security Archives - TechRepublic
Help Net Security
Help Net Security
N
News and Events Feed by Topic
Simon Willison's Weblog
Simon Willison's Weblog
G
Google Developers Blog
A
Arctic Wolf
T
The Blog of Author Tim Ferriss
博客园 - 叶小钗
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Google DeepMind News
Google DeepMind News
博客园 - 三生石上(FineUI控件)
aimingoo的专栏
aimingoo的专栏
Hacker News: Ask HN
Hacker News: Ask HN
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 司徒正美
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Privacy International News Feed
T
Troy Hunt's Blog
T
Tenable Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Recorded Future
Recorded Future
F
Fortinet All Blogs
D
DataBreaches.Net
B
Blog
T
Threat Research - Cisco Blogs
MyScale Blog
MyScale Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
The GitHub Blog
The GitHub Blog
Security Latest
Security Latest
M
MIT News - Artificial intelligence

jdhao's digital space

Conversion between base64 and OpenCV or PIL Image 腾讯云对象存储博客图床开启 CDN 加速(不需要购买额外域名) Search and Replace in Multiple Files in Vim/Neovim Change Table Column Width in LaTeX Image or Table Side by Side in LaTeX Firenvim: Neovim inside Your Browser Content inside HTML tags missing in Latest Hugo? Creating Markdown Front Matter with Ultisnips Labelme JSON 标注格式转 voc XML 格式 Nifty Nvim Techniques That Make My Life Easier -- Series 6 macOS 下如何为视频制作字幕 Running Command Asynchronously inside Neovim Resolving Merge Conflict after Git Stash Pop Pylint: command not found? A Hands-on Experience with Neovim's Built-in LSP Support How to Convert PDF to Images with Imagemagick 互联网上常用缩略语集锦 File Backup in Neovim Converting PDF Pages to Images with Poppler Nifty Nvim Techniques That Make My Life Easier -- Series 5 Neovim Configuration for System-wide Use How to sort a list of tuple or list in Python -- lambda or itemgetter? Building A Vim Statusline from Scratch 人类第一颗原子弹爆炸始末 Distributed Training in PyTorch with Horovod Learning Expect Programming Essential Knowledge about SSH Nifty LaTeX Techniques -- Series 1 更改 Adsense 邮寄地址,重新寄送 PIN Mintty Tips and Configurations Generating Table of Contents for Markdown with Tagbar Convert Python Script to Exe on Windows with Pyinstaller Ubuntu on Windows Missing after Windows Update 使用代理加速 Mac 终端下载速度 My Experience with Several Zsh Plugin Managers 深圳租房小记 How to Install zplug inside Docker Container Why don't settings inside bashrc or bash_profile take effect? Setting Up Locale in Linux 谷歌 Adsense 申请及在 Hugo 中的配置 How to Write Algorithm Pseudo Code in LaTeX Nifty Nvim Techniques That Make My Life Easier -- Series 4 A Few Grammar Questions in Writing How to Read and Write Images with Unicode Paths in OpenCV Creating A Professional Table in LaTeX with booktabs How to Create Proper Folding for Vim/Nvim Configuration Linux Tips and Tricks -- s1 JPEG Image Orientation and Exif How Do I Show the Current File Path In Neovim? JPEG Image Quality in PIL Difference between view, reshape, transpose and permute in PyTorch Convert PIL or OpenCV Image to Bytes without Saving to Disk Fast Movement and Navigation Inside Vim or Neovim Unintuitive Behaviour of Case Sensitivity in Python glob Binding Keys in Zsh 几把机械键盘试用体验 Nvim Autocompletion with Deoplete Converting Markdown to Beautiful PDF with Pandoc Exclusive and Inclusive Motion in Neovim/Vim Nifty Nvim Techniques Which Make My Life Easier -- Series 3 Why Doesn't Jedi Autocompletion Work for Some Methods Vim-like Editing inside Browser Markdown 生成 HTML 时汉字之间出现多余空格问题 小米 9 安装谷歌商店(Google Play Store)与相关配置 Create Mappings That Take A Count in Neovim Spell Checking in Nvim English Words Completion inside Neovim/Vim How to Use Python Inside Vim Script with Neovim Nifty Little Nvim Techniques to Make My Life Easier -- Series 2 Setting up Ultisnips for Neovim Mac 上罗技 M590 鼠标设置 Nifty Little Nvim Techniques to Make My Life Easier -- Series 1 A Complete Guide on Writing LaTeX with Vimtex in Neovim Manipulating Images with Alpha Channels in Pillow Sublime Text Regular Expression Cheat Sheet Cropping Rotated Rectangles from Image with OpenCV Boosting Your Productivity on Terminal with Zsh and Plugins 最新版 Rime 输入法使用 (2022 更新) Display Image with Pillow inside Ubuntu on Windows Faster Directory Navigation with z.lua Cmder Advanced Configurations Nvim-qt Settings on Windows 10 Tmux Plugin Install and Management How to Debug Python Code in Terminal Markdown Writing and Previewing in Neovim -- A Complete Guide Line Number Settings for More Efficient Movement in Neovim 两个大规模中文语料库介绍以及处理 Windows 系统下几款程序员不可不用的神器 我的 2018 阅读清单 A Complete Guide to Neovim Configuration for Python Development How Is Newline Handled in Python and Various Editors? Two Issues Related to ImageFont Module in PIL 在 Listary 中调用 GoldenDict 或欧路词典查单词 Reading and Writing Text Files on Windows The Mathematics behind Font Shapes --- Bézier Curves and More 快速识别图片字体:字体识别工具介绍 Deoplete Failed to Load at Startup after Updating Python neovim Package What Is The Difference between pip, pip3 and pip3.6 Shipped with Anaconda3? Windows 10 系统下 Neovim 安装与配置 How to Use shutil.move() on Windows and Linux
LaTeX 并排显示图像或表格
2020-03-07 · via jdhao's digital space

使用 LaTeX 写文章的时候,经常需要并排显示图片或者表格,本文总结几种实现方法。

当我们把表格或者图片并显示时,我们在不同时候需求是不一样的,有的时候我们要求几张图片或者表格是一个整体的一部分,这些小图片或者表格要有自己的 caption 以及 label;另外的时候,我们只是想并列图片或者表格来节省空间,或者产生对比,这些图片或者表格并不是一个整体,而是毫无关系,相互之间独立的(independent),也就是说这些图片(表格)有自己的 caption 和 label,并且这些 label 是独立的,举例来说,就是这些图片在引用时候,不是以 1a, 1b, 1c 这种形式呈现的,而是单独的数字编号.

对于图像,可以采用两种方式,一种是使用 LaTeX 自带的 minipage 环境,另外一种借助于 subcaption 这个库,还可以使用 subfig 这个库。 如果想要图片或者表格拥有自己的 caption 跟 label,并且整体还有一个 caption 和 label,可以使用 subcaption 与 subfig 这两个库。

图片或表格不相互独立#

使用 subcaption 的写法#

Click to view the code.
\documentclass{article}
\usepackage{graphicx}
\usepackage{subcaption}
\usepackage[capitalize]{cleveref}

\begin{document}

In~\cref{fig:test}, we show two images: \cref{fig:sub1} and \cref{fig:sub2}.

\begin{figure}[h]
    \centering
    \begin{subfigure}[t]{.5\textwidth}
        \centering
        \includegraphics[width=0.9\linewidth]{cat1.jpeg}
        \caption{caption 1}
        \label{fig:sub1}
    \end{subfigure}%
    \begin{subfigure}[t]{.5\textwidth}
        \centering
        \includegraphics[width=0.9\linewidth]{cat2.jpeg}
        \caption{caption 2}
        \label{fig:sub2}
    \end{subfigure}
    \caption{Two cats.}
    \label{fig:test}
\end{figure}

\end{document}

使用 subfig 的写法#

Click to view the code.
\documentclass{article}
\usepackage{graphicx}
\usepackage{subfig}
\usepackage[capitalize]{cleveref}

\begin{document}

In~\cref{fig:test}, we show two images: \cref{fig:sub1} and \cref{fig:sub2}.

\begin{figure}[h]
\centering
\subfloat[caption for figure1a]{
    \includegraphics[width=0.4\linewidth]{cat1.jpeg}
    \label{fig:sub1}
}
\subfloat[caption for figure1b]{
\includegraphics[width=0.4\linewidth]{cat2.jpeg}
\label{fig:sub2}
}
\caption{A figure with two subfigure}
\label{fig:test}
\end{figure}

\end{document}

上述代码,子图的 caption 默认都是在图片下面,如果想要让子图的 caption 在图片上面,需要在添加 subfig 库的时候加上一些选项,\usepackage[position=top]{subfig}, 总的图片的 caption 位置则视 caption 放置位置而定。

上述两段代码都是针对图像的,对于表格,subcaption 提供的是 subtable 环境,subfig 仍然使用 \subfloat 命令,其他的代码针对 table 做一个小修改就可以了,基本不变。

图片或表格相互独立#

如果想要各个图片或表格只是并列,相互之间独立,可以使用 minipage 环境,或者使用 parbox 也可以部分达成这种目的,

使用minipage的写法,#

Click here to view code.
\documentclass{article}
\usepackage{graphicx}
\usepackage{subfig}
\usepackage[capitalize]{cleveref}

\begin{document}

We show two images \cref{fig:sub1} and \cref{fig:sub2} below.

\begin{figure}[h]
    \centering
    \begin{minipage}[t]{.5\textwidth}
        \centering
        \includegraphics[width=0.9\linewidth]{cat1.jpeg}
        \caption{caption 1}
        \label{fig:sub1}
    \end{minipage}%
    \begin{minipage}[t]{.5\textwidth}
        \centering
        \includegraphics[width=0.9\linewidth]{cat2.jpeg}
        \caption{caption 2}
        \label{fig:sub2}
    \end{minipage}
\end{figure}

\end{document}

上面的源代码很容易看懂,不用太多解释,唯一需要注意的是第一个 minipage 环境结束后的百分号,这个百分号是必不可少的,百分号的意思就是两个 minipage 环境之间不要有空隙,紧密相连,如果没有百分号,编译以后的文档中,两个图片是上下排放的,并不是左右并列。

对百分号再举一个例子,譬如有一个单词,需要分开上下两行,但是不希望隔断,如果不加百分号,两部分中间会有一个空格,加百分号就不会有这种现象了。

可以看到,空格不见了,这就是百分号的作用。

使用parbox的写法#

Click here to view code.
\documentclass{article}
\usepackage{graphicx}
\usepackage{subfig}
\usepackage[capitalize]{cleveref}

\begin{document}

We show two images \cref{fig:sub1} and \cref{fig:sub2} below.

\begin{figure}[h]
\parbox{0.5\textwidth}{
    \centering
    \includegraphics[width=0.9\linewidth]{cat1.jpeg}
    \caption{caption 1}
    \label{fig:sub1}
}
\parbox{0.5\textwidth}{
    \centering
    \includegraphics[width=0.9\linewidth]{cat2.jpeg}
    \caption{caption 2}
    \label{fig:sub2}
}
\end{figure}

\end{document}

但是 parbox 有一个缺点,如果两个图片的 caption 的文本数量不一样或者两个图片大小不一致,不能上端对齐或者下端对齐,因而 parbox 并不是一个很好的选项,并不推荐。

上述的两段代码都是针对 figure 的,如果要并排 table,改变跟 figure 有关的代码,换成 table 相关的就可以了,不再赘言。

参考资料#