Two lstlistings side by side with refering arrow
tikzmark
, which you are loading, has a library for that purpose, listings
, which allows you to refer to lines of the code without actually modifying it. And I am using this nice answer.
\documentclass{article}
\usepackage{listings}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\usetikzmarklibrary{listings}
\lstset{language=C,
basicstyle=\ttfamily,
%frame=single,
keywordstyle=\color{blue}\ttfamily,
stringstyle=\color{red}\ttfamily,
commentstyle=\color{green}\ttfamily,
morecomment=[l][\color{magenta}]{\#}
}
\newcounter{tmkcount}
\tikzset{
use tikzmark/.style={
remember picture,
overlay,
execute at end picture={
\stepcounter{tmkcount}
},
},
tikzmark suffix={-\thetmkcount}
}
\begin{document}
%\begin{minipage}{0.8\textwidth}
\begin{tabular}{|l|p{2cm}|l|}
\multicolumn{1}{l}{\texttt{file\_x.c}} &
\multicolumn{1}{l}{} &
\multicolumn{1}{l}{\texttt{file\_y.c}}\\
\cline{1-1} \cline{3-3}
\begin{lstlisting}[language=C,name=codeL]
void foo()
{
int q = 5;
int l = 6;
bar(q, l);
}
\end{lstlisting}
\begin{tikzpicture}[use tikzmark]
\coordinate (aux) at (pic cs:line-codeL-6-end);
\end{tikzpicture}
& &
\begin{lstlisting}[language=C,name=codeR]
void bar(int a, int b)
{
...
...
...
...
...
}
\end{lstlisting}\\
\cline{1-1} \cline{3-3}
\end{tabular}
\begin{tikzpicture}[use tikzmark]
\draw[-latex] ([yshift=2ex,xshift=-3ex]aux) to[bend left=10]
node[midway,above,sloped]{(int,int)} (pic cs:line-codeR-1-start);
\end{tikzpicture}
%\end{minipage}
\end{document}
as tikz
image:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning, quotes}
\usepackage{listings}
\lstset{language=C,
basicstyle=\ttfamily,
keywordstyle=\color{blue}\ttfamily,
stringstyle=\color{red}\ttfamily,
commentstyle=\color{green}\ttfamily,
morecomment=[l][\color{magenta}]{\#}
}
\begin{document}
\begin{tikzpicture}[
node distance = 22mm,
box/.style = {draw, align=left}
]
\node (a) [box]
{\hspace*{-2em}%
\begin{lstlisting}[language=C]
void foo()
{
int q = 5;
int l = 6;
bar(q, l);
}
\end{lstlisting}
};
\node (b) [box, right=of a]
{\hspace*{-2em}%
\begin{lstlisting}[language=C]
void bar(int a, int b)
{
...
...
...
...
}
\end{lstlisting}
};
\draw[->, black!75] ([shift={(2.2,-4.4ex)}] a.west) to [pos=0.7,"{(int,int)}", sloped] ([shift={(2ex,8ex)}] b.west);
\end{tikzpicture}
\end{document}