我試圖消除使用 tikzmarkin 突出顯示表格區域時的偏移/縮排問題。
\documentclass{beamer}
\RequirePackage{booktabs,colortbl,caption,tabularx,chngcntr, tikz, comment, subfig,xcolor}
\usepackage{lmodern}
\usepackage[beamer,customcolors]{hf-tikz}
\tikzset{hl/.style={
set fill color=red!80!black!40,
set border color=red!80!black,
},
}
\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
\frametitle{Correlations}
\vspace{-2em}
\begin{tabular*}{1.00\textwidth}{@{\hskip\tabcolsep\extracolsep\fill}l*{6}r}
& $\alpha$ & $ p_L $ & $\kappa$ & $\sigma$ & $\delta$ & $ \lambda $ \\
[1.5pt] \hline
\tikzmarkin<3>[hl]{c1}$\alpha$ \tikzmarkend{c1} & \tikzmarkin<1>[hl]{a1} -0.08 \tikzmarkend{a1} & 0.05 & -0.18 & 0.18 & -0.06 & -0.18 \\ [2pt]
$ ~p_L $ & -0.07 & 0.03 & -0.08 & 0.02 & 0.09 & -0.02 \\ [2pt]
$\varepsilon$ & -0.31 & 0.05 & -0.33 & \tikzmarkin<2>[hl]{b1} 0.59 & 0.04 & -0.30 \\ [2pt]
$\mu$ & -0.33 & 0.10 & -0.39 & 0.57 \tikzmarkend{b1} & 0.07 & -0.40 \\ [2pt]
$ \frac{\mu}{\varepsilon} $ & 0.23 & -0.06 & 0.47 & -0.39 & 0.24 & 0.49 \\ [2pt]
\end{tabular*}
\end{frame}
\end{document}
例如,第一個反白的儲存格的內容 (-0.08) 向左移動。類似地,第二個突出顯示的單元格的底部單元格內容向左移動。然而,當第一列中的元素被反白時,內容會向右移動。是否可以使用 tikz 的選項解決此問題?謝謝。
答案1
刪除要反白的儲存格內容前後的空格,即:
改變這個:
& \tikzmarkin<1>[hl]{a1} -0.08 \tikzmarkend{a1} &
對此:
&\tikzmarkin<1>[hl]{a1}-0.08\tikzmarkend{a1}&
解決方案的完整 MWE:
\documentclass{beamer}
\RequirePackage{booktabs,colortbl,caption,tabularx,chngcntr, tikz, comment, subfig,xcolor}
\usepackage{lmodern}
\usepackage[beamer,customcolors]{hf-tikz}
\tikzset{hl/.style={
set fill color=red!80!black!40,
set border color=red!80!black,
},
}
\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
\frametitle{Correlations}
\vspace{-2em}
\begin{tabular*}{1.00\textwidth}{@{\hskip\tabcolsep\extracolsep\fill}l*{6}r}
& $\alpha$ & $ p_L $ & $\kappa$ & $\sigma$ & $\delta$ & $ \lambda $ \\[1.5pt] \hline
\tikzmarkin<3>[hl]{c1}$\alpha$\tikzmarkend{c1}& \tikzmarkin<1>[hl]{a1}-0.08\tikzmarkend{a1} & 0.05 & -0.18 & 0.18 & -0.06 & -0.18 \\[2pt]
$ ~p_L $ & -0.07 & 0.03 & -0.08 & 0.02 & 0.09 & -0.02 \\ [2pt]
$\varepsilon$ & -0.31 & 0.05 & -0.33 & \tikzmarkin<2>[hl]{b1}0.59 & 0.04 & -0.30 \\[2pt]
$\mu$ & -0.33 & 0.10 & -0.39 & 0.57\tikzmarkend{b1} & 0.07 & -0.40 \\[2pt]
$ \frac{\mu}{\varepsilon} $ & 0.23 & -0.06 & 0.47 & -0.39 & 0.24 & 0.49 \\[2pt]
\end{tabular*}
\end{frame}
\end{document}
答案2
因為,至少隱含地,您正在使用蒂克茲我建議使用matrix of (math) nodes
-- 請參閱手冊第 57.1 節tikz
。
\matrix {...}
這樣,您可以按照通常的方式在命令中輸入矩陣,然後套用tikz
您想要在表格「頂部」中新增的任何格式。為了讓它工作,你需要添加一個fragile
命令到投影儀並突出顯示矩陣中新增|[hl]|
至對應單元格的條目。這導致:
這是完整的程式碼:
\documentclass{beamer}
\RequirePackage{booktabs,colortbl,caption,tabularx,chngcntr, tikz, comment, subfig,xcolor}
\usetikzlibrary{matrix}
\usepackage{lmodern}
\usepackage[beamer,customcolors]{hf-tikz}
\tikzset{hl/.style={
fill=red!80!black!40,
draw=red!80!black,
rounded corners
}
}
\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile]{Correlations}
\begin{tikzpicture}
\matrix (M)[matrix of math nodes,nodes in empty cells,
row sep=2mm,column sep=2mm,
nodes={anchor=east, minimum width=2em, minimum height=2em}
]{
& \alpha& p_L & \kappa & \sigma & \delta & \lambda \\
\alpha & |[hl]|-0.08 & 0.05 & -0.18 & 0.18 & -0.06 & -0.18 \\
~p_L & -0.07 & 0.03 & -0.08 & 0.02 & 0.09 & -0.02 \\
\varepsilon& -0.31 & 0.05 & -0.33 & 0.59 & 0.04 & -0.30 \\
\mu & -0.33 & 0.10 & -0.39 & 0.57 &|[hl]| 0.07 & -0.40 \\
\frac{\mu}{\varepsilon}& 0.23&-0.06& 0.47&-0.39& 0.24 & 0.49 \\
};
\draw[thick,blue](M-1-7.south east)--(M-1-1.south west);
\end{tikzpicture}
\end{frame}
\end{document}
幾點說明:
- 我已經任意設定了
row sep=2mm,column sep=2mm
行距和列距。改變以適應您的口味 - 這
nodes in empty cells
是唯一必要的,因為矩陣中沒有條目,我使用此條目在表標題下(1,1)
繪製藍色\hrule
- 正如我所使用的,
matrix of math nodes
每個條目都是在數學模式下排版的。有一個類似的matrix of nodes
條目不處於數學模式 anchor=east
規範中的thenodes={...}
將每一列與「東」對齊- 而不是使用,我更喜歡添加框架標題作為環境的
\frametitle{...}
參數frame
- 你可能想
inner sep=1mm
在hl
樣式中添加類似的東西
答案3
如果上述答案都不適合您,一種「聰明」的解決方法是簡單地調整未突出顯示的單元格前面的空間。例如,$\epsilon$
=> { $\epsilon$}
。數字括號將阻止編譯器修剪元素前面的空格。