我是 LaTeX 新手。我正在尝试制作一个单元格内有图片的表格。ShareLatex 中的预览看起来不错,但当我将 PDF 文件导出到我的计算机时,它看起来像这样。有什么建议吗?
以下是代码:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{array}
\usepackage[a4paper, total={6in, 8in}]{geometry}
\usepackage{caption}
\usepackage{lipsum}
\usepackage{natbib}
\usepackage{graphicx}
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}
\begin{document}
\pagenumbering{gobble}
\begin{table}[ht]
\begin{center}
%\centering
%\begin{tabular}{||M{1cm}|c|M{40mm}|c|c||}
\begin{tabular}{||c| >{\centering\arraybackslash}m{0,5cm} | >{\centering\arraybackslash}m{3cm} | >{\centering\arraybackslash}m{3,5cm} | >{\centering\arraybackslash}m{2,5cm} |
>{\centering\arraybackslash}m{2,5cm} ||}
\hline
1. & & SN74HC00N & Quad 2-input NAND gate & \includegraphics[height=18mm]{74HC00.png} & \includegraphics[height=18mm]{74HC00_pin.png}\\
\hline
2. & & SN74HC02N & Quad 2-input NOR gate &
\includegraphics[height=18mm]{74HC02.png} & \includegraphics[height=18mm]{74HC02_pin.png}\\
\hline
3. & & SN74HC04N & Hex inverter & \includegraphics[height=18mm]{74HC04.png} &
\includegraphics[height=18mm]{74HC04_pin.png}\\
\hline
4. & & SN74HC08N & Quad 2-input AND gate & \includegraphics[height=18mm]{74HC08.png} & \includegraphics[height=18mm]{74HC08_pin.png}\\
\hline
5. & & SN74HC32N & Quad 2-input OR gate & \includegraphics[height=18mm]{74HC32.png} & \includegraphics[height=18mm]{74HC32_pin.png}\\
\hline
6. & & SN74HC76N & Dual J-K flip-flop, asynchronous preset and clear & \includegraphics[height=18mm]{74HC76.png} & \includegraphics[height=18mm]{74HC76_pin.png}\\
\hline
7. & & SN74HC86N & Quad 2-input XOR gate & \includegraphics[height=18mm]{74HC86.png} & \includegraphics[height=18mm]{74HC86_pin.png}\\
\hline
8. & & SN74HC153N & Dual 4-line to 1-line data selector/multiplexer, non-inverting outputs & \includegraphics[height=18mm]{74HC153.png} & \includegraphics[height=18mm]{74HC153_pin.png}\\
\hline
9. & & SN74HC190N & Synchronous presettable up/down decade counter & \includegraphics[height=18mm]{74HC190.png} & \includegraphics[height=18mm]{74HC190_pin.png}\\
\hline
10. & & SN74HC595N & 8-bit shift registers, output latches, three-state parallel outputs & \includegraphics[height=18mm]{74HC595.png} & \includegraphics[height=18mm]{74HC595_pin.png}\\
\hline
11. & & SN74HC4511AP & BCD to 7-segment decoder & \includegraphics[height=18mm]{74HC4511.png} & \includegraphics[height=18mm]{74HC4511_pin.png}\\
\hline
\end{tabular}
\end{center}
\caption*{}
\end{table}
\end{document}
答案1
您可以在列描述中的图形前添加一些空格,如下所示:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{array}
\usepackage[a4paper, total={6in, 8in}]{geometry}
\usepackage{caption}
\usepackage{lipsum}
\usepackage{natbib}
\usepackage[demo]{graphicx}
\usepackage{array}
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}
\begin{document}
\pagenumbering{gobble}
\begin{table}[ht]
\centering
\begin{tabular}{||c|
>{\centering\arraybackslash}m{0,5cm} |
>{\centering\arraybackslash}m{3cm} |
>{\centering\arraybackslash}m{3,5cm} |
>{\centering\arraybackslash\vspace{3pt}}m{2,5cm} |
>{\centering\arraybackslash\vspace{3pt}}m{2,5cm} |}
\hline
1. & & SN74HC00N & Quad 2-input NAND gate & \includegraphics[width=\linewidth]{example-image} & \includegraphics[width=\linewidth]{example-image}\\
\end{tabular}
\caption*{}
\end{table}
\end{document}
答案2
像这样?
\documentclass{article}
\usepackage[a4paper, total={6in, 8in}]{geometry}
\usepackage{caption}
\usepackage[demo]{graphicx}
% added
\usepackage[export]{adjustbox}
\newcommand\insertimage[1]{% for shorter code
\includegraphics[height=18mm,width=0.8\linewidth, % width is only for test, original images are probaly narrover
margin=0pt 3pt 0pt 3pt, valign=m]{#1}%
}
\usepackage{tabularx}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\begin{document}
\begin{table}
\centering
\caption{my table}\label{tab:ic}
\begin{tabularx}{\linewidth}{|c|c|c | C|C|C|}
\hline
1. & & SN74HC00N & Quad 2-input NAND gate & \insertimage{74HC00.png} & \insertimage{74HC00_pin.png}\\
\hline
2. & & SN74HC02N & Quad 2-input NOR gate &
\insertimage{74HC02.png} & \insertimage{74HC02_pin.png}\\
\hline
3. & & SN74HC04N & Hex inverter & \insertimage{74HC04.png} &
\insertimage{74HC04_pin.png}\\
\hline
4. & & SN74HC08N & Quad 2-input AND gate & \insertimage{74HC08.png} & \insertimage{74HC08_pin.png}\\
\hline
5. & & SN74HC32N & Quad 2-input OR gate & \insertimage{74HC32.png} & \insertimage{74HC32_pin.png}\\
\hline
6. & & SN74HC76N & Dual J-K flip-flop, asynchronous preset and clear & \insertimage{74HC76.png} & \insertimage{74HC76_pin.png}\\
\hline
7. & & SN74HC86N & Quad 2-input XOR gate & \insertimage{74HC86.png} & \insertimage{74HC86_pin.png}\\
\hline
8. & & SN74HC153N & Dual 4-line to 1-line data selector/multiplexer, non-inverting outputs & \insertimage{74HC153.png} & \insertimage{74HC153_pin.png}\\
\hline
9. & & SN74HC190N & Synchronous presettable up/down decade counter & \insertimage{74HC190.png} & \insertimage{74HC190_pin.png}\\
\hline
10. & & SN74HC595N & 8-bit shift registers, output latches, three-state parallel outputs & \insertimage{74HC595.png} & \insertimage{74HC595_pin.png}\\
\hline
11. & & SN74HC4511AP & BCD to 7-segment decoder & \insertimage{74HC4511.png} & \insertimage{74HC4511_pin.png}\\
\hline
\hline
\end{tabularx}
\end{table}
- 对于表格,我建议使用
tabularx
环境,其中最后一棵树的列是C
类型(C
是列的居中变体X
)。 - 图像自然地与其底部边框对齐。要将其更改为图像中间,请使用
valign
包中的宏adjustbox
- 对于文本的垂直居中,列类型的定义随类型而
X
改变p
m
margin=<left>, <bottom> <right> <top>
图像上方和下方的垂直空间也是通过包确定的adjustbox
- 对于表格的居中,请使用\centering.
\begin{center} ... \end{center} 仅添加不需要的垂直空间- 如你所见,表格对于一页来说太高了(因此页码出现在“BCD 到 7 段解码器”的单元格中)。这可以通过将图像高度从 18 毫米减少到 15 毫米或手动将表格拆分为两部分或将
ltablex
包添加到前言中来修复,它们结合tabularx
并longtable