2

So I just started using LateX yesterday and ran into a problem. I'm making a table where a number is circled and the whole row is crossed out. I found different codes on the internet and tried applying them to the table. Here's the code:

\documentclass[12pt,a4paper]{article}
\usepackage{amsmath,amssymb,amsthm, amsfonts}
\usepackage{tikz-inet}
\usepackage{graphicx}
\usetikzlibrary{matrix}
\usepackage{tikz}

Command to make circle:

\usetikzlibrary{fit,shapes.geometric}

\newcounter{nodemarkers}
\newcommand\circletext[1]{%
    \tikz[overlay,remember picture] 
        \node (marker-\arabic{nodemarkers}-a) at (0,1.5ex) {};%
    #1%
    \tikz[overlay,remember picture]
        \node (marker-\arabic{nodemarkers}-b) at (0,0){};%
    \tikz[overlay,remember picture,inner sep=2pt]
        \node[draw,ellipse,fit=(marker-\arabic{nodemarkers}-a.center) 
        (marker-\arabic{nodemarkers}-b.center)] {};%
    \stepcounter{nodemarkers}%
}

Command to make lines in the table:

\newcommand{\tikzmark}[2]{\tikz[overlay,remember picture,baseline] 
\node [anchor=base] (#1) {$#2$};}

\newcommand{\DrawVLine}[3][]{%
  \begin{tikzpicture}[overlay,remember picture]
    \draw[shorten <=0.3ex, #1] (#2.north) -- (#3.south);
  \end{tikzpicture}
}

\newcommand{\DrawHLine}[3][]{%
  \begin{tikzpicture}[overlay,remember picture]
    \draw[shorten <=0.2em, #1] (#2.west) -- (#3.east);
  \end{tikzpicture}
}

The table:

\begin{document}
\begin{center}
\renewcommand{\arraystretch}{1.3}
  \begin{tabular}{c|cccc}
   \multicolumn {1}{c|}{} & 60 & 110 & 80 & 110 \\ \hline

    80 & \tikzmark{topA}{3}   & \tikzmark{topB}{10}   & 
    \tikzmark{topC}{20} & \tikzmark{topD}{ \circletext{0} }  \\  

    20 & 2 & 1 & 3 &        \tikzmark{rightB}{0}     \\ 
    50 & 2,5 & 3,5 & 4 &    \tikzmark{rightC}{0}    \\ 
    210 & 4 & 5 & 9 &       \tikzmark{rightD}{0}        \\ 
    \DrawVLine[blue, thick, opacity=0.8]{topD}{rightD}
  \end{tabular}
  \end{center}
\end{document}

The table looks like this

As you can see the vertical line is too long.

Can anyone tell me where the code went wrong?

If I try to remove

\DrawVLine[blue, thick, opacity=0.8]{topD}{rightD}

it looks fine though.

  • 1
    Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. – user11232 Mar 7 '15 at 17:55
3

With this, you get correct lines

\begin{document}
\begin{center}
\renewcommand{\arraystretch}{1.3}
  \begin{tabular}{c|cccc}
   \multicolumn {1}{c|}{} & 60 & 110 & 80 & 110 \\ \hline

    80 & \tikzmark{topA}{3}   & \tikzmark{topB}{10}   &
    \tikzmark{topC}{20} & \tikzmark{topD}{ \circletext{0} }  \\

    20 & 2 & 1 & 3 &        \tikzmark{rightB}{0}     \\
    50 & 2,5 & 3,5 & 4 &    \tikzmark{rightC}{0}    \\
    210 & 4 & 5 & 9 &       \tikzmark{rightD}{0}          %% remove \\ here
  \end{tabular}
  \DrawVLine[blue, thick, opacity=0.8]{topD}{rightD}      %% move this after \end{tabular}
  \end{center}
\end{document}

enter image description here

The \\ in the last row introduces an additional row and the \DrawVLine has its natural place outside the tabular environment.

  • why do you need the intermediate marks? – percusse Mar 7 '15 at 22:32
  • @percusse I don't know. May be the OP has some purpose for them. – user11232 Mar 7 '15 at 23:06
  • @Labbiqa Please remember that you can accept the answers that best fit your needs by clicking the green check mark besides them. In case of doubt please see How do you accept an answer. Once you get 15 rep points, you can also up vote them. – user11232 Mar 7 '15 at 23:09

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.