0

I'd like to

  • put two minted source code blocks in two beamer columns
  • with arrows pointing between the two (tikzmark-based)
  • and use adjustbox to scale the code blocks down to columnwidth

This works ok without adjustbox (based on Is it possible to use tikzmark inside minted? and Drawing overlay graphics over minted code, mostly). See the first frame in the sample below.

However, when surrounding the minted blocks with adjustbox/varwidth environments for scaling, the tikzmarks appear to be off and store wrong positions (which make intuitive sense). See second frame in the example below. Putting the second tikzpicture at different places in the frame makes a difference, but all options I tried produced in correct results.

(Side remark: of course these code examples are stupid; just to make the effect pronounced).

Illustration: The first version works, but does not scale the code blocks.

Correct arrow position, without adjustbox scaling

With an adjustbox, the red arrow is all over the place:

With adjustbox, arrow is in wrong place

\documentclass[ignorenonframetext,nooutline]{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\usepackage{minted}
\usepackage{adjustbox}
\usetheme[hideothersubsections]{Goettingen}

\begin{document}


\begin{frame}[fragile]{Minted columns without adjustbox}

  \begin{columns}
    \tiny
    \begin{column}{0.5\columnwidth}

\begin{minted}[frame=lines,linenos=true,autogobble,escapeinside=??]{c}
int main (void)
{
    zmq_send (sender, "Some long text to have a wide line", 5, 0); ?\tikzmark{start}?

    return 0;
}

\end{minted}

    \end{column}

    \begin{column}{0.5\columnwidth}

\begin{minted}[frame=lines,linenos=true,autogobble,escapeinside=??]{c}
int main (void)
{
// some comment  
// some more comment 

    ?\tikzmark{eend}? zmq_receive (s, buffer, 100, 0); 
}

\end{minted}

    \end{column}

    \begin{tikzpicture}[remember picture]
      \draw [overlay, ->, line width=5pt, red] (pic cs:start) -- (pic cs:eend);
    \end{tikzpicture}

  \end{columns}
\end{frame}

% ------------------------

\begin{frame}[fragile,label={sec:org93808b5}]{With adjust box}
  \begin{columns}
    \begin{column}{0.5\columnwidth}
      \begin{block}{Sender}
        \begin{adjustbox}{width=0.35\columnwidth}
          \begin{varwidth}{\columnwidth}

\begin{minted}[frame=lines,linenos=true,mathescape=true,escapeinside=??]{c}
int main (void)
{
    zmq_send (sender, "Some long text to have a wide line", 5, 0); ?\tikzmark{start1}?

    return 0;
}
\end{minted}

          \end{varwidth}
        \end{adjustbox}
      \end{block}
    \end{column}

    \begin{column}{0.5\columnwidth}
      \begin{block}{Receiver}
        \begin{adjustbox}{width=0.4\columnwidth}
          \begin{varwidth}{\columnwidth}

\begin{minted}[frame=lines,linenos=true,mathescape=true,escapeinside=??]{c}
int main (void)
{
// some comment  
// some more comment 

    ?\tikzmark{end2}? zmq_receive (s, buffer, 100, 0); 
}
\end{minted}

          \end{varwidth}
        \end{adjustbox}
      \end{block}
    \end{column}

      \begin{tikzpicture}[remember picture]
        \draw[overlay, ->, line width=5pt, red] (pic cs:start1) -- (pic cs:end1);
      \end{tikzpicture}

  \end{columns}
\end{frame}


\end{document}
  • For what it is worth: there does not seem to be any nice way of doing this. breaklines options of minted is not ideal, but seems to do the job for me. (listings package not much different in this respect). Would be interesting to understand the interplay of tikzmark and adjustbox better, though... – Holger Karl Apr 16 '18 at 18:31
1

Scaling fonts is not a good idea, either manually select an appropriate font size (which is already very small, so probably nobody will be able to read it) or you could use a linebreak instead of scaling:

% !TeX program = txs:///arara
% arara: pdflatex: {synctex: on, interaction: nonstopmode, shell: yes}
\documentclass{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\usepackage{minted}

\begin{document}

\begin{frame}[fragile]{Minted columns without adjustbox}
  \begin{columns}
    \tiny
    \begin{column}{0.48\columnwidth}
            \begin{minted}[frame=lines,linenos=true,autogobble,escapeinside=??,breaklines]{c}
                int main (void)
                {
                    zmq_send (sender, "Some long text to have a wide line", 5, 0); ?\tikzmark{start}?

                    return 0;
                }
            \end{minted}
    \end{column}
    \begin{column}{0.48\columnwidth}
            \begin{minted}[frame=lines,linenos=true,autogobble,escapeinside=??,breaklines]{c}
                int main (void)
                {
                // some comment  
                // some more comment 

                    ?\tikzmark{eend}? zmq_receive (s, buffer, 100, 0); 
                }
            \end{minted}
    \end{column}
    \begin{tikzpicture}[remember picture]
      \draw [overlay, ->, line width=5pt, red] (pic cs:start) -- (pic cs:eend);
    \end{tikzpicture}
  \end{columns}
\end{frame}

\end{document}

enter image description here

  • As I said, the example is artifical. Scaling will be necessary for longer examples; the \tiny is in here just for demonstration. I'd much rather not use font scaling, of course - as you correctly, point out. – Holger Karl Apr 8 '18 at 8:23

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.