KristofferC / PGFPlotsX.jl

Plots in Julia using the PGFPlots LaTeX package
Other
301 stars 40 forks source link

Allow settings axis width and height from an external latex document #261

Open KristofferC opened 3 years ago

KristofferC commented 3 years ago

A common workflow with PGFPlotsX.jl is that you export a figure .tex file (without a preamble) and then include it in a main .tex document. Often, you want to be able to set the width and height of this figure from the main .tex document. What you can do is to include the figure with \includegraphics and then use e.g. the width option to set the width of the figure. This however leads to the drawback that the text of the figure is scaled as well, meaning it looks inconsistent with the rest of the document.

The way to properly resize a figure (without scaling the text) is to set the width and height options of the axis. This is however something you do from within the exported .tex file which is a bit awkward.

What other software does, for example matlab2tikz (https://tomlankhorst.nl/matlab-to-latex-with-matlab2tikz/) is that they allow you to set the height and width like this:

\begin{figure}[!htb]
\centering
    \setlength\fheight{0.35\textwidth} 
    \setlength\fwidth{0.85\textwidth}
    \input{res_cb_stress.tex}
\end{figure}

The fheight and fwidth are set from the main tex file and there is no need to modify the exported figure .tex file if one wants to change its size. This does not scale the figure text.

Having some option of exporting a figure to support this workflow probably makes sense.

KristofferC commented 3 years ago

Alternatively, it is already possible to do this from PGFPlotsX:

image

So maybe we should just add some docs on how to do this.

tpapp commented 3 years ago

I think that just documenting the preamble solution would be best, as it makes the variables explicit.

KristofferC commented 3 years ago

Agree