2

I am unable to control the line spacing between the last line of itemize and the next line as shown in the figure. Can someone suggest a solution to fix this please? I also would like to know if I can get more compact list.

\documentclass[10pt,a4paper,oneside]{article}
\usepackage[a4paper,left=0.9in,right=0.9in,top=1in,bottom=1in]{geometry}
\usepackage{longtable}
\usepackage{enumitem}

\renewcommand{\familydefault}{\sfdefault}


\begin{document}

    \scriptsize
    \begin{minipage}[t]{0.5\textwidth}
        \begin{longtable}[t]{|p{1.0cm}|p{5.5cm}|}
            \hline
            \bf{Head 1} & \textbf{Head 2} \\\hline\hline 
            \texttt{A} & Department 
            \begin{itemize} \setlength{\itemsep}{0pt}
                \item \texttt{A} - Apple
                \item \texttt{B} - Boy
                \item \texttt{C} - Cat
                \item \texttt{D} - Dog
            \end{itemize}\\
            \texttt{E} &  Elephant \\   
            \texttt{F} &  Fan \\   
            \hline
        \end{longtable}
    \end{minipage}%

\end{document}

output

  • 2
    Have a look at this question, maybe that helps. BTW, why do you put longtable inside a minipage? – Arash Esbati Aug 27 '16 at 17:11
  • I'm genuinely a little confused about how you got that output when you have \[ and \] instead of [ and ], e.g. \documentclass\[10pt,a4paper,oneside\]{article}. I mean, I'm assuming you must have generated your output with a totally different file, but if so, what happened between creating that file and writing this question :S :S Also \end{document} shouldn't have a ] after it – Au101 Aug 27 '16 at 17:41
  • There were characters that got I added when I was dragging the image. Had to redo it but I missed some of these weird symbols. – xinit Aug 27 '16 at 17:45
2

Two variations on the layout. I reduced the indent of the list and the vertical spacing w.r.t. the surrounding text.

Note an optional argument to a command or an environment, has be delimited by a pair of brackets ([option]), not between a pair of bracket commands (\[option\]). Also font commands such as \bf have been deprecated for more than 20 years. Use the \textbf{…} command instead or the \bfseries switch.

Last, not least, as @Zarko pointed, a long table is made to break across pages, and a minipage cannot. You can use the multicols environment instead.

\documentclass[10pt,a4paper,oneside]{article}
\usepackage[a4paper,hmargin=0.9in, vmargin=1in]{geometry}
\usepackage{longtable}
\usepackage{enumitem}

\renewcommand{\familydefault}{\sfdefault}

\begin{document}
\scriptsize
\begin{minipage}[t]{0.5\textwidth}
\renewcommand\arraystretch{1.33}
    \begin{longtable}[t]{|p{1.0cm}|p{5.5cm}|}
        \hline
        \textbf{Head 1} & \textbf{Head 2} \\\hline\hline
        \texttt{A} & Department
            \begin{itemize}[wide = 0.5em, nosep, after=\vspace{-\baselineskip}]
                \item \texttt{A} - Apple
                \item \texttt{B} - Boy
                \item \texttt{C} - Cat
                \item \texttt{D} - Dog
            \end{itemize}\\
        \texttt{E} & Elephant \\
        \texttt{F} & Fan \\
        \hline
    \end{longtable}
\end{minipage}%

\begin{minipage}[t]{0.5\textwidth}
\renewcommand\arraystretch{1.33}
    \begin{longtable}[t]{|c|p{5.5cm}|}
        \hline
        \textbf{Head 1} & \textbf{Head 2} \\\hline\hline
        \texttt{A} & Department
            \begin{itemize}[wide = 0.5em, nosep, after=\vspace{-\baselineskip}]
                \item \texttt{A} - Apple
                \item \texttt{B} - Boy
                \item \texttt{C} - Cat
                \item \texttt{D} - Dog
            \end{itemize}\\
        \texttt{E} & Elephant \\
        \texttt{F} & Fan \\
        \hline
    \end{longtable}
\end{minipage}%
\end{document} 

enter image description here

  • The table environment longatble suppose to be over many pages .. so put it in minipage hasn't sense. – Zarko Aug 27 '16 at 18:05
  • @zarko, I am new a newbie in the land of latex and trying to reuse some working parts to get job done within deadline. No philosophical reason, only desperation! – xinit Aug 27 '16 at 18:12
  • @Zarko: Perfectly right. I'll add it to the answer. – Bernard Aug 27 '16 at 18:24
4

If you load the enumitem package, then you can set options for lists (single or multiple of them), including the command you need which is after=. For example, if you write after=\vspace{\baselineskip}, that's what will happen after the list.

If you want a more compact list, you can also use negative values, like itemsep=-1mm. In any case, check how I used these commands, because the way you used is not the standard one. To align the longtable to the left, add the optional argument [l].

Also, make sure you check your code, you have a lot of \[\] where they shouldn't be, maybe a result of search and replace.

Output

enter image description here

Code

\documentclass[10pt,a4paper,oneside]{article}
\usepackage[a4paper,left=0.9in,right=0.9in,top=1in,bottom=1in]{geometry}
\usepackage{longtable}
\usepackage{enumitem}

\renewcommand{\familydefault}{\sfdefault}

\begin{document}
\scriptsize
%\begin{minipage}[t]{0.5\textwidth}
    \begin{longtable}[l]{|p{1.0cm}|p{5.5cm}|}
        \hline
        \bf{Head 1} & \textbf{Head 2} \\\hline\hline 
        \texttt{A} & Department 
            \begin{itemize}[itemsep=0pt, after=\vspace{-1ex}]
                \item \texttt{A} - Apple
                \item \texttt{B} - Boy
                \item \texttt{C} - Cat
                \item \texttt{D} - Dog
            \end{itemize}\\
        \texttt{E} &  Elephant \\   
        \texttt{F} &  Fan \\   
        \hline
    \end{longtable}
%\end{minipage}%
\end{document}
  • In answer you also should emphasize, that OP wrongly use options of packages and environments. Instead in [... ] he/she put them in math environment \[...\] ... Given MWE is not possible to compile. – Zarko Aug 27 '16 at 17:17
  • @Zarko Ah yes, I did notice that. – Alenanno Aug 27 '16 at 17:18
  • The weird characters got inserted while I was trying to upload picture. It was a working example. Sorry about that. :( – xinit Aug 27 '16 at 18:05
3

I do not know what is requestes behind of this table design, however, I will design as follows:

\documentclass[10pt,a4paper,oneside]{article}
\usepackage[a4paper,hmargin=0.9in, vmargin=1in]{geometry}
\usepackage{tabularx}
\usepackage{enumitem}

\renewcommand{\familydefault}{\sfdefault}

\begin{document}
\renewcommand\arraystretch{1.2}
    \begin{tabularx}{0.5\textwidth}{|>{\ttfamily}c|>{\ttfamily}X|}
        \hline
\textbf{\textsf{Head 1}} & \textbf{\textsf{Head 2}} \\\hline\hline
        A & Department
            \begin{itemize}[wide = 0.5em, nosep, after=\vspace{-\baselineskip}]
                \item A - Apple
                \item B - Boy
                \item C - Cat
                \item D - Dog
            \end{itemize}\\
        E & Elephant \\
        F & Fan \\
        \hline
    \end{tabularx}
\end{document}

i.e. without minipages, with use of tabularx, which span table to desired width and define font family in column options. This make code more concise and less prone for errors. Above MWE gives:

enter image description here

Addendum: If you for columns head use thead macro from makecell package, you can obtain:

enter image description here

The needed changes of above MWE are:

\usepackage{makecell,tabularx}
\renewcommand\theadfont{\bfseries\sffamily}
\usepackage{enumitem}

\renewcommand{\familydefault}{\sfdefault}

\begin{document}
\renewcommand\arraystretch{1.2}
    \begin{tabularx}{0.5\textwidth}{|>{\ttfamily}c|>{\ttfamily}X|}
        \hline
\thead{Head 1} & \thead{Head 2} \\\hline\hline
... <further is the same as in above MWE > ...
  • Maybe a twocolumns{2} environment, if there must be text next to the table? – Bernard Aug 27 '16 at 18:22
  • Maybe. Who knows? This is not evident from question. – Zarko Aug 27 '16 at 18:44
  • Thanks a lot @Zarko. Will try to use the approach. Initially I did not use longtables at all, my problem was alignment and auto-resizing of table to width and auto-folding of text to table size, which was not working for various combinations that I was trying from net. And in many cases, even minipages were not starting at left, for reasons I could not comprehend at all. If only I could have found a side-by-side tables that resize nicely with folding text to proper width! – xinit Aug 29 '16 at 8:03

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.