答案1
您不需要使用外部程式進行裁切副本,只需向\includegraphics
.此 MWE 顯示相同的圖像兩次(重新命名為image.png
),有或沒有無用的背景。兩個圖像都位於帶框的盒子內以顯示邊緣:
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\section*{Original image}
\fbox{\includegraphics[width=\linewidth]{image.png}}
\section*{Trimmed and clipped image}
\fbox{\includegraphics[width=\linewidth,trim=6.5cm 6cm 6.5cm 4cm,clip]{image.png}}
\end{document}
編輯:由於目標似乎是自動裁剪更多以避免裁剪副本,但據我所知,這已經在評論中使用外部工具完美解決了,這只是在 MWE 中付諸實踐。以下代碼在上述 MWE 中加入了窮人的宏:
\section*{Automatic crop}
Note: compile with \verb|--shell-escape|\\
\newcommand\cropped[1]{%
\immediate\write18{convert -trim #1.png #1cropped.png}%
\includegraphics[width=\linewidth]{#1cropped.png}}
\fbox{\cropped{image}}
將自動產生此圖像:
事實上,裁剪並不是真正由 LaTeX 製作的,需要一個額外的文件,但誰在乎呢?反正是邊跑邊做的pdflatex
。