0

I was making some tables for the documentation but this particular table struck me. It has entries in a form of sentences and phrases as shown in the figure below....

enter image description here

I made that table using Microsoft Word but I wonder if we can do the same in Latex...

My question is...

Can we make the same table as above using Latex? If yes...how?

Update: There is one good answerer that showed how it is done, but for some unknown reasons, when I copy and pasted the poster's code, the PDF output looks awful...like this below...

enter image description here

How to resolve it? It is close to what I want....

3

A solution based on tabularx and enumitem. Note you don't really need multirow here.

\documentclass[10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[showframe]{geometry}
\usepackage{array}
\usepackage{enumitem}
\usepackage{tabularx, caption}
\captionsetup{skip=6pt}
\usepackage{ragged2e}
\makeatletter
\newcommand*{\compress}{\@minipagetrue}
\makeatother

\begin{document} 

   \begin{table}[!htb]
    \sffamily\small
    \setlength{\tabcolsep}{4pt}
    \setlength{\extrarowheight}{2pt}
    \centering
    \caption{Some caption} \label{table-test}
    \begin{tabularx}{\linewidth}{|p{1.4cm}|p{1.5cm}| >{\compress\RaggedRight}X|*{3}{p{21mm}|}}
    \hline
    Test case & Action & ~Test procedure & Expected result & Actual result & Remarks\\
    \hline
    {Login} & User login & 
    \begin{enumerate}[wide=0pt, leftmargin=*, itemsep=0pt, after=\leavevmode\vspace*{-\dimexpr\topsep+\partopsep}]
    \item Provide username and password
    \item Validate all fields have been filled
    \item Goes to the Main Site
    \end{enumerate}
    & Successfully
    logged in & Successfully logged in & Logged in \\
    \cline{2-2} \cline{4-6}
    & Missing credentials & & ... & ... & Cannot log in\\[3cm]
    \hline
    \end{tabularx}
    \end{table}

\end{document} 

enter image description here

  • hey...uhmmm how do you put a caption on the table above? – zZ_LateX_HaterZ_zZ Aug 6 '18 at 9:05
  • @zZ_LateX_HaterZ_zZ: You have to nest the code in a table` environment and add \caption{...}\label{xxx} (the latter for cross-references). Please see my updated answer. – Bernard Aug 6 '18 at 10:15
2

You are right, it is hard to convince LaTeX to create such an unappealing table, but of course it can be done. ;-)

\documentclass[10pt]{article}
\usepackage[margin=1in]{geometry}
\usepackage{array,multirow}
\begin{document}
\sffamily\small
\begin{tabular}{|p{1.5cm}|p{1cm}|@{}p{3cm}|*{3}{p{2.5cm}|}}
\hline
Test case & Action & ~Test procedure & Expected result & Actual result & Remarks\\
\hline
\multirow{2}{=}{Login} & User login & \multirow{2}{=}{
\begin{enumerate}
\item Provide username and password
\item Validate all fields have been filled
\item Goes to the Main Site
\end{enumerate}
} & Successfully
logged in & Successfully logged in & logged in \\[3cm]
\cline{2-2} \cline{4-6}
& Missing credentials & & \dots & \dots & Cannot log in\\[3cm]
\hline
\end{tabular}
\end{document}

enter image description here

  • When I copy and pasted your code, the PDF output looks odd. – zZ_LateX_HaterZ_zZ Jul 19 '18 at 6:21
  • @zZ_LateX_HaterZ_zZ I guess you copied only the table, not the 10pt in \documentclass[10pt]{article} nor \sffamily\small. To very first approximation you may just make the third column wider, e.g. @{}p{5cm} instead of @{}p{3cm}. – user121799 Jul 19 '18 at 6:29
  • I copied all your code you've typed....yes.... – zZ_LateX_HaterZ_zZ Jul 19 '18 at 6:32
  • @zZ_LateX_HaterZ_zZ Strange. Which LaTeX distribution do you use? I use TeXLive 2018, which I update on a regular basis, and compile the above with pdflatex. – user121799 Jul 19 '18 at 6:34
  • 2
    @zZ_LateX_HaterZ_zZ all questions are clearer if they have a complete small document as marmot used in this answer. If you think things are not working, post a version of the document here to your question, and show the log file or output screenshot – David Carlisle Jul 19 '18 at 7:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.