Export figure for LaTeX documents

版本 1.1.0 (4.4 KB) 作者: Andrea La Spina
High-precision tool to export a figure to pdf matching the font size and the text width of a LaTeX document.
51.0 次下载
更新时间 2022/6/29

查看许可证

The script "main.m" shows some examples of how to export a figure to pdf to precisely match the font size adopted in the LaTeX document "latex.m" (change file name to "latex.tex" when compiling).
It can be useful to export high-quality figures for scientific papers to match the style of the specific journal.
Each figure requires two parameters:
  • TextWidthRatio, defining the quantity (width of the figure)/(total width of the text in the LaTeX document). To exploit the entire width of the page, use TextWidthRatio=1.00 for a single figure, TextWidthRatio=0.49 for two subfigures placed next to each other, etc.
  • FigRatio, defining the quantity (height of the figure)/(width of the figure). In case the axes are "constrained" (for example by setting "axis equal"), this represents only an initial guess.
The function cropFigure() adopts an iterative procedure to gradually move the position of the axes in order to eliminate the white margins.
At each step, a lower-quality temporary png file is written and read making sure that no colored pixel (supposedly containing useful information) exits the margins of the figure.
Once the optimal position of the axes has been found, the resulting figure is exported to a high-quality pdf file, ready to be included in the LaTeX document via the \includegraphics command.
Simply run "main.m" in Matlab and compile "latex.tex" with your preferred LaTex compiler (for example TeXmaker) to see a few examples.
If you find this tool useful, please give feedback.

引用格式

Andrea La Spina (2024). Export figure for LaTeX documents (https://www.mathworks.com/matlabcentral/fileexchange/114350-export-figure-for-latex-documents), MATLAB Central File Exchange. 检索来源 .

MATLAB 版本兼容性
创建方式 R2019b
兼容任何版本
平台兼容性
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
版本 已发布 发行说明
1.1.0

.

1.0.2

.

1.0.1

.

1.0.0