2

I am new to LaTeX. I am trying to make a table with pictures inside the cells. Preview in ShareLatex looks fine, but when I export PDF file to my computer it looks like this. Any suggestions?

Preview in Adobe Acrobat Pro

Here is the code:

\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}
Alina
  • 23
  • Welcome to TeX.SE! Please try to give as a MWE (https://tex.meta.stackexchange.com/questions/228/ive-just-been-asked-to-write-a-minimal-example-what-is-that) [just the needed -minimum- code to reproduce the problem]. Images of code doesn't really help as to reproduce the problem and find a solution. – koleygr Sep 19 '17 at 21:05
  • instead of code image please copy code to question. it is not fun retype a code if they already exist :-). in code we can easily show how to solve your problem. – Zarko Sep 19 '17 at 21:11
  • Possible duplicate of https://tex.stackexchange.com/questions/170941/images-in-table-going-over-cell-lines or https://tex.stackexchange.com/questions/68590/images-inside-table-are-drawn-on-top-of-cell-borders or https://tex.stackexchange.com/questions/41788/image-in-table-covers-horizontal-line-above-it (Every one of these has a different answer but all of them can work -I suppose- for you too) – koleygr Sep 19 '17 at 21:13
  • Off-topic: Hahaha! Everyone who see the question is trying to edit (Itried too)... This is funny! – koleygr Sep 19 '17 at 21:15
  • The image is just an a print screen to illustrate how the website displayed the code when I tied to copy in in to the question. – Alina Sep 19 '17 at 21:15
  • Try adding, just after \begin{table}, \setlength{\extrarowheight}{3pt}. Also replace the center environment inside table with \centering. – Bernard Sep 19 '17 at 21:16
  • @Alina Just leave a line after "Here is the code:", paste it there and then select it (all the code pasted) and press the {} button. – koleygr Sep 19 '17 at 21:21
  • That did not solve the problem, @Bernard – Alina Sep 19 '17 at 21:29
  • Thank you for the links, @koleygr :) Unfortunately none of them worked for me – Alina Sep 19 '17 at 21:32
  • Add a bit space before the graphics by using this column definition: >{\centering\arraybackslash\vspace{3pt}}m{2,5cm} – Ulrike Fischer Sep 19 '17 at 21:33
  • @Alina: When you zoom in when viewing the PDF in your viewer, do the lines still disappear? – Werner Sep 19 '17 at 21:37
  • @Ulrike Fischer: Thank you so much!! It worked! :D I could not mark your answer as the best one since it is written as a comment :/ – Alina Sep 19 '17 at 21:38
  • @Werner: yes, they did – Alina Sep 19 '17 at 21:39

2 Answers2

2

like this?

enter image description here

\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}
  • for table i suggest to use tabularx environment, where last tree columns are of C type (C is centering variant of X column).
  • images are natural aligned with its bottom border. to change this to the middle of image iis used macro valign from package adjustbox
  • for vertical centering of texts the definition of X column type is changed from p type to m type
  • vertical space above and below image is determined with margin=<left>, <bottom> <right> <top> also from adjustbox package -for centering of table please use anly \centering.\begin{center} ... \end{center} only add undesired vertical space
  • as can you see, table is to tall for one page (consequently page number appear in cell with "BCD to 7-segment decoder". this can be repaired with reduce images heights from 18mm to 15mm or manually split table into two parts or add ltablex package to preamble, which combine tabularx and longtable
Zarko
  • 296,517
1

You can add some space before the graphics in the column description like this:

\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}

enter image description here

Ulrike Fischer
  • 327,261