3

I need to convert a latex output to an SVG extending to just a figure.

\documentclass{standalone}
%\documentclass{article}
%\pagestyle{empty}

\usepackage{nicematrix,tikz}

\begin{document}
$\begin{pNiceMatrix}[create-medium-nodes]
  1    & 2 & -3  \\
 -2    & 0 & 4
\CodeAfter
\begin{tikzpicture}
    \draw (2-3) circle (2cm) ; % just to prove this is visible
    \node[right] at (1-3.east) {\quad this is some explanatory text that\\
                               \quad should be displayed in standalone\\
                               \quad on three lines?!\\
                               } ;
\end{tikzpicture}
\end{pNiceMatrix}$
\end{document}

If I use \documentclass{article} I get the figure I want, but embedded in a full page. If I use \documentclass{standalone} I only get the matrix, not the circle or the text.

  1. Why does standalone loose some of the figure elements?
  2. Why are the newlines in the text of the node not honored?
  3. Any changes to the code above that might yield output cropped to just the figure?
5
  • 2
    +1 Hi and welcome. Indeed there is a problem and I don't know how to solve it. The only thing I can say is that to align the text, just add \node[right,align=left]{...}.
    – AndréC
    Aug 29 '20 at 6:58
  • Have you considered using TikZ's built-in matrices? (Check out "matrices of nodes" in the manual.) Aug 29 '20 at 9:24
  • no. I need features that only nicematrix provides. I did find a workaround, though: use {article}, convert latex output to svg, and then crop the svg with inkscape. Clumsy, but at least no manual steps. I do wonder what breaks, though?!
    – ea42_gh
    Aug 29 '20 at 11:11
  • tex.stackexchange.com/questions/559564/… You can try this. Using clip=false inside an axis environment in your tikzpicture, or making all your drawings with \addplot
    – Á. Iborra
    Aug 29 '20 at 11:13
  • IIRC, the varwidth option for standalone honors linefeeds. Or you can put it into a minipage, \parbox or tabular. Aug 29 '20 at 12:52
1

In the environments of nicematrix, the code-after (which can be set after the keyword \CodeAfter like in this question) is executed after a \tikzset{every picture/.style = {overlay,remember picture}}.

Since we are in overlay mode, the objects drawn in the code-after are not taken into account to the computation of the bounding box.

So, the output is the expected output.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.