2

This is a follow up question to my earlier question here (Thanks to @Gonzalo for nice answer). I want to make the same table with boxes in article documentclass. My MWE

\documentclass{article}
\usepackage{booktabs}
\usepackage{tikz}
\usetikzlibrary{tikzmark}

\usepackage[english]{babel}
\usepackage{blindtext}

\newcommand\FramedBox[3][]{%
 \draw[red!80!black,rounded corners,#1]    
   ([xshift=-1ex,yshift=3ex]pic cs:#2)      
      rectangle    
        ([xshift=1ex,yshift=-1ex]pic cs:#3); 
     }


\begin{document}

\blindtext

\begin{table}[ph]
\protect\caption{Genotype-by-Environment Means}
\centering{}%
\begin{tabular}{l|cccccc|c}
\hline 
 & \multicolumn{6}{c|}{Environment} & \tabularnewline
\cline{2-7} 
Genotype & $1$ & $2$ & $\ldots$ & $j$ & $\ldots$ & $e$ & Mean\tabularnewline
\hline 
$1$ & $\overline{Y}_{11.}$ & $\overline{Y}_{12.}$ & $\ldots$ & $\overline{Y}_{1j.}$ & $\ldots$ & $\overline{Y}_{1e.}$ & $\overline{Y}_{1..}$\tabularnewline
$2$ & $\overline{Y}_{21.}$ & $\overline{Y}_{22.}$ & $\ldots$ & $\overline{Y}_{2j.}$ & $\ldots$ & $\overline{Y}_{2e.}$ & $\overline{Y}_{2..}$\tabularnewline
$\vdots$ & $\vdots$ & $\vdots$ & $\ddots$ & $\vdots$ & $\ddots$ & $\vdots$ & $\vdots$\tabularnewline
$i$ & $\overline{Y}_{i1.}$ & $\overline{Y}_{i2.}$ & $\ldots$ & $\overline{Y}_{ij.}$ & $\ldots$ & $\overline{Y}_{ie.}$ & $\overline{Y}_{i..}$\tabularnewline
$\vdots$ & $\vdots$ & $\vdots$ & $\ddots$ & $\vdots$ & $\ddots$ & $\vdots$ & $\vdots$\tabularnewline
$g$ & $\overline{Y}_{g1.}$ & $\overline{Y}_{g2.}$ & $\ldots$ & $\overline{Y}_{gj.}$ & $\ldots$ & $\overline{Y}_{ge.}$ & $\overline{Y}_{g..}$\tabularnewline
\hline 
Mean & $\overline{Y}_{.1.}$ & $\overline{Y}_{.2.}$ & $\ldots$ & $\overline{Y}_{.j.}$ & $\ldots$ & $\overline{Y}_{.e.}$ & $\overline{Y}_{...}$\tabularnewline
\hline 
\end{tabular}
\end{table}


\Blindtext

\begin{tikzpicture}[remember picture,overlay] 
\FramedBox{starta}{enda} 
\FramedBox{startc}{endc} 
\FramedBox[draw=cyan]{startb}{endb} 
\end{tikzpicture}


\begin{table}
\caption{Genotype-by-Environment Means}
\centering{}%
\begin{tabular}{lccccccc}
\toprule 
 & \multicolumn{6}{c}{Environment} & 
\tabularnewline
\cmidrule{2-7} 
Genotype & $1$ & $2$ & $\ldots$ & $j$ & $\ldots$ & $e$ & Mean
\tabularnewline
\midrule
$1$ & $\overline{Y}_{11.}$ & $\overline{Y}_{12.}$ & $\ldots$ 
  & \tikzmark{startb}$\overline{Y}_{1j.}$ & $\ldots$ & $\overline{Y}_{1e.}$ & $\overline{Y}_{1..}$
\tabularnewline
$2$ & $\overline{Y}_{21.}$ & $\overline{Y}_{22.}$ & $\ldots$ 
  & $\overline{Y}_{2j.}$ & $\ldots$ & $\overline{Y}_{2e.}$ & $\overline{Y}_{2..}$
\tabularnewline
$\vdots$ & $\vdots$ & $\vdots$ & $\ddots$ & $\vdots$ & $\ddots$ 
  & $\vdots$ & $\vdots$
\tabularnewline
$i$ & \tikzmark{starta}$\overline{Y}_{i1.}$ & $\overline{Y}_{i2.}$ 
  & $\ldots$ & $\overline{Y}_{ij.}$ & $\ldots$ & $\overline{Y}_{ie.}$ 
  & $\overline{Y}_{i..}$ \tikzmark{enda} 
\tabularnewline
$\vdots$ & $\vdots$ & $\vdots$ & $\ddots$ & $\vdots$ & $\ddots$ 
  & $\vdots$ & $\vdots$
\tabularnewline
$g$ & $\overline{Y}_{g1.}$ & $\overline{Y}_{g2.}$ & $\ldots$ 
  & $\overline{Y}_{gj.}$ & $\ldots$ & $\overline{Y}_{ge.}$ & $\overline{Y}_{g..}$
\tabularnewline
\midrule
Mean & $\overline{Y}_{.1.}$ & \tikzmark{startc}$\overline{Y}_{.2.}$\tikzmark{endc} & $\ldots$ 
  & $\overline{Y}_{.j.}$\tikzmark{endb} & $\ldots$ & $\overline{Y}_{.e.}$ & $\overline{Y}_{...}$
\tabularnewline
\bottomrule 
\end{tabular}
\end{table}

\blindtext
\Blindtext

\end{document}

It works fine. But if I export this to LyX then I have problems. In LyX Version 2.1.0beta2 even after multiple compilations, node positions are wrong. See attached figure. enter image description here

Any idea to do this in LyX. Thanks


Edited

Using @Gonzalo code, every thing works fine but after exporting to LyX I'm getting the following output with problems with node positions.

enter image description here

MYaseen208
  • 8,587

2 Answers2

2

Something strange happens on import to LyX. If you look at the source code generated by LyX, the start of the tikzpicture is

\begin{tikzpicture}{[}remember picture,overlay{]}

while it should be

\begin{tikzpicture}[remember picture,overlay]

Note that on import, \begin{tikzpicture} is in an ERT, while [remember picture,overlay] is not. Move the latter part into the ERT, and it works fine here.

Torbjørn T.
  • 206,688
  • Thanks Torbjorn for your answer. Now it is working perfectly. But I have to accept the answer of @Gonzalo because that is more elaborate. – MYaseen208 Mar 04 '14 at 16:28
  • Thanks for finding this bug, Torbjørn T. I reported it and it was fixed (by Georg Baum) in LyX for version 2.2.0. For more details, see http://www.lyx.org/trac/ticket/9011 – scottkosty Dec 30 '14 at 18:20
1

If the table floats, the boxes will end in a different page; to prevent this, draw the boxes inside the corresponding table environment:

\documentclass{article}
\usepackage{booktabs}
\usepackage{tikz}
\usetikzlibrary{tikzmark}

\usepackage[english]{babel}
\usepackage{blindtext}

\newcommand\FramedBox[3][]{%
  \draw[red!80!black,rounded corners,#1]    
    ([xshift=-1ex,yshift=3ex]pic cs:#2)      
      rectangle    
   ([xshift=1ex,yshift=-1ex]pic cs:#3); 
}

\begin{document}

\begin{table}[p]
\begin{tikzpicture}[remember picture,overlay] 
\FramedBox{starta}{enda} 
\FramedBox{startc}{endc} 
\FramedBox[draw=cyan]{startb}{endb} 
\end{tikzpicture}
\caption{Genotype-by-Environment Means}
\centering{}%
\begin{tabular}{lccccccc}
\toprule 
 & \multicolumn{6}{c}{Environment} & 
\tabularnewline
\cmidrule{2-7} 
Genotype & $1$ & $2$ & $\ldots$ & $j$ & $\ldots$ & $e$ & Mean
\tabularnewline
\midrule
$1$ & $\overline{Y}_{11.}$ & $\overline{Y}_{12.}$ & $\ldots$ 
  & \tikzmark{startb}$\overline{Y}_{1j.}$ & $\ldots$ & $\overline{Y}_{1e.}$ & $\overline{Y}_{1..}$
\tabularnewline
$2$ & $\overline{Y}_{21.}$ & $\overline{Y}_{22.}$ & $\ldots$ 
  & $\overline{Y}_{2j.}$ & $\ldots$ & $\overline{Y}_{2e.}$ & $\overline{Y}_{2..}$
\tabularnewline
$\vdots$ & $\vdots$ & $\vdots$ & $\ddots$ & $\vdots$ & $\ddots$ 
  & $\vdots$ & $\vdots$
\tabularnewline
$i$ & \tikzmark{starta}$\overline{Y}_{i1.}$ & $\overline{Y}_{i2.}$ 
  & $\ldots$ & $\overline{Y}_{ij.}$ & $\ldots$ & $\overline{Y}_{ie.}$ 
  & $\overline{Y}_{i..}$ \tikzmark{enda} 
\tabularnewline
$\vdots$ & $\vdots$ & $\vdots$ & $\ddots$ & $\vdots$ & $\ddots$ 
  & $\vdots$ & $\vdots$
\tabularnewline
$g$ & $\overline{Y}_{g1.}$ & $\overline{Y}_{g2.}$ & $\ldots$ 
  & $\overline{Y}_{gj.}$ & $\ldots$ & $\overline{Y}_{ge.}$ & $\overline{Y}_{g..}$
\tabularnewline
\midrule
Mean & $\overline{Y}_{.1.}$ & \tikzmark{startc}$\overline{Y}_{.2.}$\tikzmark{endc} & $\ldots$ 
  & $\overline{Y}_{.j.}$\tikzmark{endb} & $\ldots$ & $\overline{Y}_{.e.}$ & $\overline{Y}_{...}$
\tabularnewline
\bottomrule 
\end{tabular}
\end{table}

\blindtext

\end{document}

enter image description here

I only used [p] as placemnet specifier for the example to make the table float to the second page.

Gonzalo Medina
  • 505,128
  • Thanks @Gonzalo for your help again. Your provided code works fine in LaTeX but if I export this to LyX, still I've the same problem in LyX. Might some issue with LyX. – MYaseen208 Mar 04 '14 at 13:25