这是我之前的问题的后续问题这里(感谢@Gonzalo 的精彩回答)。我想制作与文章中相同的表格documentclass
。我的 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}
它工作正常。但如果我将其导出到,LyX
就会出现问题。即使LyX Version 2.1.0beta2
经过多次编译,节点位置仍然错误。见附图。
有什么想法可以做到这一点LyX
。谢谢
已编辑
使用@Gonzalo 代码,一切运行正常,但导出到 LyX 后,我得到以下输出,其中节点位置存在问题。
答案1
如果表格浮动,框将结束在不同的页面;为了防止这种情况,请在相应的table
环境内绘制框:
\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}
我仅使用[p]
placemnet 说明符作为示例,使表浮动到第二页。
答案2
导入 LyX 时会发生一些奇怪的事情。如果你查看 LyX 生成的源代码,你会tikzpicture
发现
\begin{tikzpicture}{[}remember picture,overlay{]}
虽然应该
\begin{tikzpicture}[remember picture,overlay]
请注意,导入时,\begin{tikzpicture}
在 ERT 中,而不在[remember picture,overlay]
。将后一部分移入 ERT,它在这里可以正常工作。