2

I have an exam where my students should connect two objects in different columns on a page. The two columns are one with text alternatives and one with pictures/formulae. I want to draw a red line connecting the correct object for the corrected sheet, how can I do it?

\begin{minipage}[t]{0.5\textwidth}
{\bf A} \\ \vspace{10 mm}
(1) Surjektivitet \\ \vspace{20 mm}
(2) Reflexivitet \\ \vspace{20 mm}
(3) Symmetri  \\ \vspace{20 mm}
(4) Injektivitet \\  \vspace{20 mm}
(5) Transitivitet \\ \vspace{30 mm}

Lycka till!
\end{minipage}\begin{minipage}[t]{0.5\textwidth}
{\bf B}  \\ \vspace{10 mm}
(a)\\ 
\begin{center}
\vspace{-10 mm} \includegraphics[width=0.4\textwidth]{Injection} \\  \vspace{20 mm}
\end{center}
\stepcounter{footnote}
(b) \textbf{$\forall a \in A, \;\; a\mathcal{R}a$ }. \footnote{  $\forall a \in A$, läses ut som för varje element $a$ i mängden $A$ så gäller\dots}\\ \vspace{20 mm}

(c) \textbf{$\forall x,y,z \in X,$ $(x\mathcal{R}y \wedge y\mathcal{R}z  \Rightarrow x\mathcal{R}z)$ }\\ \vspace{20 mm}

(d)\\   \begin{center}  
\vspace{-10 mm} \includegraphics[width=0.4\textwidth]{Surjection}\\    \end{center}
\end{minipage}

Ex. (3) connects to (b) with a red arrow.

migrated from stackoverflow.com Jun 19 '13 at 16:12

This question came from our site for professional and enthusiast programmers.

3

This can be done with \tikzmark. First you place some marks and then use the \Connect command to connect the appropriate marks:

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{enumitem}
\usepackage{tikz}
\usetikzlibrary{calc}

\newcommand\tikzmark[1]{%
  \tikz[remember picture,overlay]\node (#1) {};%
}

\newcommand\Connect[3][]{%
\tikz[remember picture,overlay]
  \draw[->,red,>=latex,#1] (#2.north east) -- ( $ (#3.north west) + (-20pt,0) $ );%
}

\begin{document}

\noindent\begin{minipage}[t]{0.5\textwidth}
{\bfseries A}
\begin{enumerate}[label=(\arabic*),itemsep=20mm]
\item Surjektivitet\tikzmark{starta}
\item Reflexivitet\tikzmark{startb}
\item Symmetri\tikzmark{startc}
\item Injektivitet\tikzmark{startd}
\item Transitivitet\tikzmark{starte}
\end{enumerate}
Lycka till!
\end{minipage}%
\begin{minipage}[t]{0.5\textwidth}
{\bfseries B}
\begin{enumerate}[label=(\alph*),itemsep=20mm]
\item\tikzmark{enda}  
\begin{center}
\includegraphics[width=0.4\textwidth,height=1cm]{Injection}
\end{center}
%\stepcounter{footnote}
\item\tikzmark{endb} $\forall a \in A, \;\; a\mathcal{R}a$.\footnote{$\forall a \in A$, läses ut som för varje element $a$ i mängden $A$ så gäller\dots}
\item\tikzmark{endc} $\forall x,y,z \in X,$ $(x\mathcal{R}y \wedge y\mathcal{R}z  \Rightarrow x\mathcal{R}z)$
\item\tikzmark{endd}
\begin{center}  
\includegraphics[width=0.4\textwidth,height=1cm]{Surjection} 
\end{center}
\end{enumerate}
\end{minipage}

\begin{tikzpicture}[remember picture,overlay]
\Connect{startb}{endb}
\Connect{starte}{endc}
\end{tikzpicture}

\end{document}

enter image description here

The demo option for graphicx simply replaces actual figures with black rectangles; do not use that option in your actual document. I also changed the height of the included images, just for the example code.

Not related to the question, but you were using a lot of manual adjustments that are not really necessary (and, in some case, are not correct); in particular, I used the enumitem package to customize some enumerate environments, allowing you to minimize the manual interventions.

  • Thank you! Your answer is greatly appreciated. Will consider the other improvements too. – AndyMeow Jun 24 '13 at 8:56

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.