# Inserting an image properly in a table

I'd like to insert those lines that from "Foo" point to the four different rows in the table.

I've tries inserting an image but it doesn't come out right (please ignore the bad quality of the lines and the table not resembling the one above):

Here's the minimal example:

\documentclass[12pt]{book}

\usepackage[utf8]{inputenc}
\usepackage[a4paper]{geometry}

\usepackage{graphicx}
\usepackage{multirow}
\usepackage{array}

\pagestyle{empty}

\begin{document}

\setlength{\extrarowheight}{5pt}

\begin{tabular}{ c c c c c c }

& & A & B & C & D \\ \cline {2-6}
\multirow{4}{*}{Foo \includegraphics[scale=0.5]{IMAGE HERE}}    & 1 & foo A1 & foo B1 & foo C1 & foo D1 \\
& 2 & foo A2 & foo B2 & foo C2 & foo D2 \\
& 3 & foo A3 & foo B3 & foo C3 & foo D3 \\
& 4 & foo A4 & foo B4 & foo C4 & foo D4 \\

\end{tabular}

\end{document}


Obviously, if you know of a "Tex-native" way to do this without using images, which quality will inevitably go poor when inserted, that would be a perfect solution.

-

Similar to the solution I provided in How to draw arrows between parts of an equation to show the Math Distributive Property (Multiplication)?, you can use \tikzmark as defined in Adding a large brace next to a body of text. Each endpoint of the line is identified by \tikzmark, and the \DrawLines macro draws the line between each of the nodes.

You can adjust the shorten <=<size> parameter to start the lines a little later which achieves a nice effect. Here is the result with shorten <=7pt:

Curved lines can also be obtained by specifying in=<angle> and out=<angle> options. For example using \DrawLinesCurved instead of DrawLines you get:

## Notes:

• This requires two runs. Once to determine the begin and end point of the lines, and the second to draw them.
• The colors of the 4 lines are passed as parameters to \DrawLines.
• I used the -latex arrows here, but if arrows are not desired this option can be removed.
• I used \raisebox to adjust the position of the text (as requested in the comments).

## Code:

\documentclass[12pt]{book}

\usepackage[utf8]{inputenc}
\usepackage[a4paper]{geometry}
\usepackage{graphicx}
\usepackage{array}
\usepackage{tikz}
\usetikzlibrary{calc,shapes}

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

\newcommand{\DrawLinesCurved}[4]{%
\begin{tikzpicture}[overlay,remember picture,-latex,shorten >=1pt,shorten <=1pt, thick]
\draw[out=80,  in=180, #1] (a.north) to (b.north west);
\draw[out=40,  in=180, #2] (a.north) to (c.north west);
\draw[out=320, in=180, #3] (a.north) to (d.north west);
\draw[out=275, in=180, #4] (a.north) to (e.north west);
\end{tikzpicture}
}

\newcommand{\DrawLines}[4]{%
\begin{tikzpicture}[overlay,remember picture,-latex,shorten >=1pt,shorten <=1pt, thick]
\draw[#1] (a.north) to (b.north west);
\draw[#2] (a.north) to (c.north west);
\draw[#3] (a.north) to (d.north west);
\draw[#4] (a.north) to (e.north west);
\end{tikzpicture}
}

\pagestyle{empty}
\begin{document}

\setlength{\extrarowheight}{5pt}
\raisebox{-12pt}{Foo\tikzmark{a}}\hspace*{1.0cm}
\begin{tabular}[c]{ c c c c c c }
& A & B & C & D \\ \cline {2-6}
\tikzmark{b}1 & foo A1 & foo B1 & foo C1 & foo D1 \\
\tikzmark{c}2 & foo A2 & foo B2 & foo C2 & foo D2 \\
\tikzmark{d}3 & foo A3 & foo B3 & foo C3 & foo D3 \\
\tikzmark{e}4 & foo A4 & foo B4 & foo C4 & foo D4 \\
\end{tabular}
\DrawLines{red}{blue}{green}{orange}
\end{document}

-
This is perfect! Just one thing: is it possible to make it so that "Foo" stays in the middle (when using multirow) so that the arrows come out symmetrical? :D It's just a "visual thing", as I think your answer pretty much does what I need. :D –  Alenanno Feb 25 '12 at 0:24
@Alenanno: I placed the text Foo is outside of the table. The pacement of Foo has nothing to do with this solution. You can move it as desired and the arrows will adjust with respect to where it is placed. –  Peter Grill Feb 25 '12 at 0:32
Ok, I'll try it and let you know. Another thing, is the color of the arrows editable? By the way, I +1'ed your answer. :) –  Alenanno Feb 25 '12 at 0:38
@Alenanno: The color of the arrows is specified in the call to \DrawLines. I also updated the solution to show how to move the location of the \Foo text. –  Peter Grill Feb 25 '12 at 1:00
Last thing and then I'll stop nagging you :D Can I choose to use lines instead of arrows? –  Alenanno Feb 25 '12 at 1:27

\documentclass[12pt]{book}

\usepackage[utf8]{inputenc}
\usepackage[a4paper]{geometry}

\usepackage{graphicx}
\usepackage{multirow}
\usepackage{array,calc,pict2e}

\pagestyle{empty}

\begin{document}

\setlength{\extrarowheight}{5pt}
\setlength\unitlength{\baselineskip + \extrarowheight}

\begin{tabular}{ c c c c c c }

& & A & B & C & D \\ \cline {2-6}
\multirow{4}{*}{\begin{picture}(1,1)
\put(.5,.5){\makebox(0,0)[r]{foo }}
\put(.5,.5){\vector(2,3){1}}
\put(.5,.5){\vector(2,1){1}}
\put(.5,.5){\vector(2,-1){1}}
\put(.5,.5){\vector(2,-3){1}}
\end{picture}}    & 1 & foo A1 & foo B1 & foo C1 & foo D1 \\
& 2 & foo A2 & foo B2 & foo C2 & foo D2 \\
& 3 & foo A3 & foo B3 & foo C3 & foo D3 \\
& 4 & foo A4 & foo B4 & foo C4 & foo D4 \\

\end{tabular}

\end{document}

-
May I suggest a \usepackage{pict2e}? –  Martin Schröder Feb 25 '12 at 0:53
I guess so, I forgot that package actually worked these days, for so many years it just printed a message saying it didn't exist:-) added –  David Carlisle Feb 25 '12 at 1:05
Thank you too David, I upvoted your answer too! :) –  Alenanno Feb 25 '12 at 1:47

Just to complement Peter's nice answer, I have used the matrix library. This might be of use since you have already typed in the tabular format so I just copied and pasted it.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix,calc}
\begin{document}
\begin{tikzpicture}
\matrix[matrix of nodes] (footable) {
&A & B & C & D \\
1 & foo A1 & foo B1 & foo C1 & foo D1 \\
2 & foo A2 & foo B2 & foo C2 & foo D2 \\
3 & foo A3 & foo B3 & foo C3 & foo D3 \\
4 & foo A4 & foo B4 & foo C4 & foo D4 \\
};
\draw (footable-2-1.north west) -- (footable-2-5.north east);
\node (Foo) at ([xshift=-1cm]$(footable-3-1.west)!0.5!(footable-4-1.west)$) {Foo};
\foreach \x in {2,...,5}{
\draw (Foo) -- (footable-\x-1);%replace (Foo) with (Foo.east) to focus the arrow origins
}
\end{tikzpicture}
\end{document}


So, basically matrix library allows us to type in the tabular data. Then we put a node of which coordinates are calculated by obtaining the middle point of 3rd and 4th rows and shifting it by -1cm on the horizontal axis via calc library. Then a foreach argument draws the lines.

-
Thank you! I have accepted Peter's answer, but I upvoted yours too because it's interesting as well! :) –  Alenanno Feb 25 '12 at 1:46