[置顶] 泰晓 RISC-V 实验箱,配套 30+ 讲嵌入式 Linux 系统开发公开课
Centering (horizontally and vertically) an image in Latex
by falcon of TinyLab.org 2014/01/02
Background
In Open-Shell-Book project, I want to add an image as the book cover.
First off, I tried to convert the image to a pdf file with the convert.im6 tool from imagemagick, and then, used pdftk to merge this cover pdf file with the book pdf file, it basically worked, but the bookmarks lost.
$ sudo apt-get install imagemagick pdftk $ convert cover.png cover.pdf $ pdftk A=cover.pdf B=book.pdf cat A B output book-with-cover.pdf
Google gave me gs and pdf-merge.py, both of them didn’t work well, the former although reserved the bookmarks, but their links didn’t point to the right places, the latter fixed up part of the links, but also broke the accessing of the codes: the content listed as code can not be searched/copied in pdf readers.
Issue
So, I plan to use Latex itself to build the cover, but to do so, I must center the image horizontally and vertically.
Solution
To fix up this issue, after reading several pages of Google results, I get this solution:
- Horizontally center the image with
\begin{table} ... \end{table}
- Vertically center the image with the export feature of the
adjustbox
package:\includegraphics[width=1.5\textwidth,center]{image.png}
The full code looks like:
\begin{table} \includegraphics[width=1.5\textwidth,center]{cover.png} \end{table}
To simplify the using, our Open-Shell-Book defined a new command for the cover usage:
\documentclass[a4paper,oneside]{book} \usepackage[export]{adjustbox}[2011/08/13] \usepackage{graphicx} \newcommand\makecover[1]{ \clearpage \begin{table} \includegraphics[width=1.5\textwidth,center]{#1} \end{table} \addtocounter{page}{-1} \newpage} \begin{document} \makecover{cover.png} \end{document}
猜你喜欢:
- 我要投稿:发表原创技术文章,收获福利、挚友与行业影响力
- 知识星球:独家 Linux 实战经验与技巧,订阅「Linux知识星球」
- 视频频道:泰晓学院,B 站,发布各类 Linux 视频课
- 开源小店:欢迎光临泰晓科技自营店,购物支持泰晓原创
- 技术交流:Linux 用户技术交流微信群,联系微信号:tinylab
支付宝打赏 ¥9.68元 | 微信打赏 ¥9.68元 | |
请作者喝杯咖啡吧 |