![在单元格中添加文本而不移动其他任何内容](https://linux22.com/image/382832/%E5%9C%A8%E5%8D%95%E5%85%83%E6%A0%BC%E4%B8%AD%E6%B7%BB%E5%8A%A0%E6%96%87%E6%9C%AC%E8%80%8C%E4%B8%8D%E7%A7%BB%E5%8A%A8%E5%85%B6%E4%BB%96%E4%BB%BB%E4%BD%95%E5%86%85%E5%AE%B9.png)
我想向其中一个单元格添加文本,这样它就不会移动页面中表格的位置,也不会改变列中文本的对齐方式。我制作了一个我想要的小模型。我认为这就像在列中添加标签一样。
这是我目前为止生成的表格。我还有数据文件,通过使用 包含在代码中filecontents
。
\documentclass{article}
\usepackage{amssymb, amsmath, amsthm}
\usepackage[margin=1in]{geometry}
\usepackage{fancyhdr}
\usepackage{appendix}
\usepackage{pgfplots, pgfplotstable}
\pgfplotsset{compat=1.15}
\usepackage{booktabs}
\usepackage{multicol}
\usepackage{filecontents}
\begin{filecontents}{lmax.dat}
wavelength T abs
400 70.4 0.152
410 63.9 0.194
420 57.8 0.238
430 52.9 0.277
440 49.5 0.305
450 47.4 0.324
460 46.9 0.329
470 47.8 0.321
480 49.9 0.302
490 53.1 0.275
500 57.3 0.242
510 62.2 0.206
520 67.2 0.173
530 72.3 0.141
540 78.3 0.106
550 82.8 0.082
\end{filecontents}
\pagestyle{fancy}
\begin{document}
\begin{table}[!htbp]
\centering
\caption{Absorbance and transmittance for solution E at various wavelengths}
\label{tab:lmax}
\vspace{1em}
\pgfplotstabletypeset[
every head row/.style={before row=\toprule, after row=\midrule},
every last row/.style={after row=\bottomrule},
columns/wavelength/.style={column name={$\lambda$ (nm)}},
columns/T/.style={fixed, fixed zerofill, precision=1, column name={$\%T$}},
columns/abs/.style={fixed, fixed zerofill, precision=3, column name={$A=-\log(T)$}}
]{lmax.dat}
\end{table}
\end{document}
答案1
对我来说,这看起来像是 的工作tikzmark
。在此解决方案中,您只需指定要标记的条目,即行和列。我所做的就是告诉 pgfplotstable 将 tikzmark 附加到相应的条目,然后让 tikzmark 发挥其魔力。
\documentclass{article}
\usepackage{amssymb, amsmath, amsthm}
\usepackage[margin=1in]{geometry}
\usepackage{fancyhdr}
\usepackage{appendix}
\usepackage{pgfplots, pgfplotstable}
\usetikzlibrary{tikzmark}
\pgfplotsset{compat=1.15}
\usepackage{booktabs}
\usepackage{multicol}
\usepackage{filecontents}
\begin{filecontents}{lmax.dat}
wavelength T abs
400 70.4 0.152
410 63.9 0.194
420 57.8 0.238
430 52.9 0.277
440 49.5 0.305
450 47.4 0.324
460 46.9 0.329
470 47.8 0.321
480 49.9 0.302
490 53.1 0.275
500 57.3 0.242
510 62.2 0.206
520 67.2 0.173
530 72.3 0.141
540 78.3 0.106
550 82.8 0.082
\end{filecontents}
\pagestyle{fancy}
\begin{document}
\begin{table}[!htbp]
\centering
\caption{Absorbance and transmittance for solution E at various wavelengths}
\label{tab:lmax}
\vspace{1em}
\pgfplotstabletypeset[
every row 6 column 2/.style={postproc cell content/.style={@cell
content=##1\tikzmark{x}}},
every head row/.style={before row=\toprule, after row=\midrule},
every last row/.style={after row=\bottomrule},
columns/wavelength/.style={column name={$\lambda$ (nm)}},
columns/T/.style={fixed, fixed zerofill, precision=1, column name={$\%T$}},
columns/abs/.style={fixed, fixed zerofill, precision=3, column name={$A=-\log(T)$}}
]{lmax.dat}
\end{table}
\begin{tikzpicture}[overlay,remember picture]
\node[anchor=west] at ([yshift=3pt]pic cs:x) {$(\lambda_\mathrm{max})$};
\end{tikzpicture}
\end{document}
全新版本的 tikzmark 库,可在这里,使这项事业更加简单。与positioning
图书馆一起真的只需输入给定条目即可轻松添加内容1mm right of
。无需手动调整。;-)
\documentclass{article}
\usepackage{amssymb, amsmath, amsthm}
\usepackage[margin=1in]{geometry}
\usepackage{fancyhdr}
\usepackage{appendix}
\usepackage{pgfplots, pgfplotstable}
\usetikzlibrary{tikzmark,positioning}
\pgfplotsset{compat=1.15}
\usepackage{booktabs}
\usepackage{multicol}
\usepackage{filecontents}
\begin{filecontents}{lmax.dat}
wavelength T abs
400 70.4 0.152
410 63.9 0.194
420 57.8 0.238
430 52.9 0.277
440 49.5 0.305
450 47.4 0.324
460 46.9 0.329
470 47.8 0.321
480 49.9 0.302
490 53.1 0.275
500 57.3 0.242
510 62.2 0.206
520 67.2 0.173
530 72.3 0.141
540 78.3 0.106
550 82.8 0.082
\end{filecontents}
\pagestyle{fancy}
\begin{document}
\begin{table}[!htbp]
\centering
\caption{Absorbance and transmittance for solution E at various wavelengths}
\label{tab:lmax}
\vspace{1em}
\pgfplotstabletypeset[
every row 6 column 2/.style={postproc cell content/.style={@cell
content=\tikzmarknode{x}{##1}}},
every head row/.style={before row=\toprule, after row=\midrule},
every last row/.style={after row=\bottomrule},
columns/wavelength/.style={column name={$\lambda$ (nm)}},
columns/T/.style={fixed, fixed zerofill, precision=1, column name={$\%T$}},
columns/abs/.style={fixed, fixed zerofill, precision=3, column name={$A=-\log(T)$}}
]{lmax.dat}
\end{table}
\begin{tikzpicture}[overlay,remember picture]
\node[right=1mm of x] {$(\lambda_\mathrm{max})$};
\end{tikzpicture}
\end{document}
答案2
一个简单但硬编码的解决方案是tikz overlay
根据current page
尺寸使用手动定位:
\documentclass{article}
\usepackage{amssymb, amsmath, amsthm}
\usepackage[margin=1in]{geometry}
\usepackage{fancyhdr}
\usepackage{appendix}
\usepackage{pgfplots, pgfplotstable}
\pgfplotsset{compat=1.15}
\usepackage{booktabs}
\usepackage{multicol}
\usepackage{tikz}
\usepackage{filecontents}
\begin{filecontents}{lmax.dat}
wavelength T abs
400 70.4 0.152
410 63.9 0.194
420 57.8 0.238
430 52.9 0.277
440 49.5 0.305
450 47.4 0.324
460 46.9 0.329
470 47.8 0.321
480 49.9 0.302
490 53.1 0.275
500 57.3 0.242
510 62.2 0.206
520 67.2 0.173
530 72.3 0.141
540 78.3 0.106
550 82.8 0.082
\end{filecontents}
\newcommand{\tikzmark}[1]{\begin{tikzpicture}[overlay, remember picture]\coordinate (#1);\end{tikzpicture}}
\pagestyle{fancy}
\begin{document}
\begin{table}[!htbp]
\centering
\caption{Absorbance and transmittance for solution E at various wavelengths}
\label{tab:lmax}
\vspace{1em}
\pgfplotstabletypeset[
every head row/.style={before row=\toprule, after row=\midrule},
every last row/.style={after row=\bottomrule},
columns/wavelength/.style={column name={$\lambda$ (nm)}},
columns/T/.style={fixed, fixed zerofill, precision=1, column name={$\%T$}},
columns/abs/.style={fixed, fixed zerofill, precision=3, column name={$A=-\log(T)$}}
]{lmax.dat}
\end{table}
\begin{tikzpicture}[overlay, remember picture]
\node at ([shift={(2.5,6.9)}]current page.center){$(\lambda_{max})$};
\end{tikzpicture}
\end{document}
当然这必须在页面具有最终形式之后完成,并且shift命令里面的数字将是其他数字。
输出:
答案3
该解决方案不需要页面坐标,但它仍然需要计算相对于 pgfplotstable(节点)边缘的偏移量。
虽然额外的文本对 pgfplotstable 没有影响,但它确实会影响居中(略微)。
\documentclass{article}
\usepackage{amssymb, amsmath, amsthm}
\usepackage[margin=1in]{geometry}
\usepackage{fancyhdr}
\usepackage{appendix}
\usepackage{pgfplots, pgfplotstable}
\pgfplotsset{compat=1.15}
\usepackage{booktabs}
\usepackage{multicol}
%\usepackage{tikz}% already laoded
\usepackage{filecontents}
\begin{filecontents}{lmax.dat}
wavelength T abs
400 70.4 0.152
410 63.9 0.194
420 57.8 0.238
430 52.9 0.277
440 49.5 0.305
450 47.4 0.324
460 46.9 0.329
470 47.8 0.321
480 49.9 0.302
490 53.1 0.275
500 57.3 0.242
510 62.2 0.206
520 67.2 0.173
530 72.3 0.141
540 78.3 0.106
550 82.8 0.082
\end{filecontents}
\pagestyle{fancy}
\begin{document}
\begin{table}[!htbp]
\centering
\caption{Absorbance and transmittance for solution E at various wavelengths}
\label{tab:lmax}
\vspace{1em}
\begin{tikzpicture}
\node[inner sep=0pt] (A) {\pgfplotstabletypeset[
every head row/.style={before row=\toprule, after row=\midrule},
every last row/.style={after row=\bottomrule},
columns/wavelength/.style={column name={$\lambda$ (nm)}},
columns/T/.style={fixed, fixed zerofill, precision=1, column name={$\%T$}},
columns/abs/.style={fixed, fixed zerofill, precision=3, column name={$A=-\log(T)$}}
]{lmax.dat}};
\node[right, yshift={\dimexpr -9.4mm-5\baselineskip}, xshift=-8mm] at (A.north east) {$(\lambda_\text{max})$};
\end{tikzpicture}
\end{table}
\end{document}