1

My question might be similar with this items list inside table cell are not well aligned, but the solution was not fit in my case.

with this code:

\documentclass[a4paper, 11pt]{article} 
\usepackage[margin=2cm]{geometry} % changes the margin
\usepackage{enumitem}
\usepackage{amssymb}
\usepackage{titlesec}
\usepackage{indentfirst}
\usepackage{longtable}
\usepackage{blindtext}


%% Create a very compact enumerated list environment
\newlist{myenum}{enumerate}{1}
\setlist[myenum]{label=\arabic*., nosep, wide, 
             leftmargin=*, % hanging indentation
             before=\vspace{-0.57\baselineskip},
             after =\vspace{-0.8\baselineskip}} % reducing vertical   space
%---------------------Need to Simplify This-----------------------------%
\newlist{myenum2}{enumerate}{1}
\setlist[myenum2]{label=\alph*), nosep, wide, 
             leftmargin=*, % hanging indentation
             before=\vspace{-0.57\baselineskip},
             after =\vspace{-0.8\baselineskip}} % reducing vertical space
\newlist{myenum3}{enumerate}{1}
\setlist[myenum3]{label=\arabic*), nosep, wide, 
             leftmargin=*, % hanging indentation
             before=\vspace{-0.57\baselineskip},
             after =\vspace{-0.8\baselineskip}} % reducing vertical space
\newlist{myenum4}{enumerate}{1}
\setlist[myenum4]{label=\arabic*., nosep, wide, 
             leftmargin=*, % hanging indentation
             before=\vspace{-0.57\baselineskip},
             after =\vspace{-0.8\baselineskip},
             start=2} % reducing vertical space
\newlist{myenum5}{enumerate}{1}
\setlist[myenum5]{label=\arabic*., nosep, wide, 
             leftmargin=*, % hanging indentation
             before=\vspace{-0.57\baselineskip},
             after =\vspace{-0.8\baselineskip},
             start=3} % reducing vertical space
\newlist{myenum6}{enumerate}{1}
\setlist[myenum6]{label=\arabic*., nosep, wide, 
             leftmargin=*, % hanging indentation
             before=\vspace{-0.57\baselineskip},
             after =\vspace{-0.8\baselineskip},
             start=4} % reducing vertical space
\newlist{myenum7}{enumerate}{1}
\setlist[myenum7]{label=\arabic*., nosep, wide, 
             leftmargin=*, % hanging indentation
             before=\vspace{-0.57\baselineskip},
             after =\vspace{-0.8\baselineskip},
             start=5} % reducing vertical space               

\renewcommand\thesection{\Alph{section}.}
\renewcommand\thesubsection{\arabic{subsection}.}
%% Re-format the font size of "the section"
% {11} is the desired font size
% {15} is the vertical spacing, perhaps refers to 1.5 lines?
% \selectfont is for un-bold the sub-section
\titleformat{\section}
{\normalfont\fontsize{11}{.5em}\bfseries}{\thesection}{.5em}
    {}
\titleformat{\subsection}
{\normalfont\fontsize{11}{.5em}\selectfont}{\thesubsection}{.5em}
    {}
\titlespacing % starred version: first paragraph is not indented
{\subsection} % <command>
{0em} % <left>
{.4em} % <before-sep>
{.3em} % <after-sep>

\setlength\parindent{1cm} 

% Avoid hypenation (breaking sentences in paragraph)
\tolerance=1
\emergencystretch=\maxdimen
\hyphenpenalty=10000
\hbadness=10000

\begin{document}
%------------------------------Section D---------------------------------------------%
\section{Some Text Here}
\begin{longtable}{@{}p{0.3\textwidth}cp{0.65\textwidth}}
%% Subsection 1
\begin{myenum} \item Some Text Here \end{myenum} & : & \blindtext \\
%% Subsection 2
\begin{myenum4} \item Some Text Here \end{myenum4} & : & \blindtext \\
%% Subsection 3
\begin{myenum5} \item Some Text Here \end{myenum5} & : & \begin{myenum3}
\item Some Text Here;
\item Some Text Here;
\item Some Text Here;
\item Some Text Here;
\item Some Text Here;
\item Some Text Here.
\end{myenum3}\\
%% Subsection 4
\begin{myenum6} \item Some Text Here \end{myenum6} & : &   \begin{myenum2} 
\item \blindtext; 
\item \blindtext;  
\end{myenum2}\\
%% Subsection 5
\begin{myenum7} \item{Some Text Here} \end{myenum7} & : & \blindtext.\\
\end{longtable}
\end{document}

This resulted in this[output1][][1]]1[output2]2

My questions are:

  1. I know with \newlist and \setlist, I can create a custumized enumerated list in first column, but is there any more elegant way? answered
  2. How can I produce a table span multiple pages with combination of numbered list in first column, some text in the second column, : symbol in third column, and numbered list in fourth column and keep them vertically align?
  3. And how can I reduced unnecessary vertical space between \section and the text after it? answered

Any help would be greatly appreciated.

  • 1
    are you sure that you want a longtable here? It is almost always better to use a list rather than a tabular layout for such things (apart from anything else, that allows page breaking within an item) – David Carlisle Feb 23 '18 at 10:54
  • 1
    Why are you using so many different enumerate-like envirfonments? – Mico Feb 23 '18 at 10:55
  • @DavidCarlisle I not sure myself, but that was the best I can came up with, because it was a part of a bit complex report and I just follow the default format provided. – Bram Setyadji Madusuyatno Feb 23 '18 at 12:06
  • @Mico I used to work with simple tabular with enumerate/itemize, but I find it difficult to insert an automatic numbering for the first column. That is why i used different set of \newlist and \setlist for each individual numbering list. :( – Bram Setyadji Madusuyatno Feb 23 '18 at 12:10
1

If the only reason for using a custom enumerate environment is to automatically insert a counter in the first column, I suggest you proceed as follows. Observe that both the longtable and the tabular environments feature an column (of type N) which is programmed increment the counter and then print it out immediately.

Note that one can easily cross-reference specific rows via the usual \label-\ref mechanism.

enter image description here

\documentclass[a4paper, 11pt]{article}
\usepackage[margin=2cm]{geometry}
\usepackage{array,longtable,etoolbox,lipsum}
\setlength\extrarowheight{2pt} % for a more open "look" of tabular material
\newcolumntype{P}[1]{p{#1\textwidth}}

\newcounter{rownum}
\newcolumntype{N}{>{\refstepcounter{rownum}\therownum}l}
% Automate resetting of counter to 0 at the start of a tabular-like env.:
\AtBeginEnvironment{tabular}{\setcounter{rownum}{0}}
\AtBeginEnvironment{tabular*}{\setcounter{rownum}{0}}
\AtBeginEnvironment{tabularx}{\setcounter{rownum}{0}}
\AtBeginEnvironment{longtable}{\setcounter{rownum}{0}}

\begin{document}

\begingroup  % localize the following settings
\setlength\tabcolsep{0pt} % <--- important
\setlength\LTleft{0pt} \setlength\LTright{0pt}

\begin{longtable}{@{\extracolsep{\fill}} N P{0.32} P{0.63}} 
   % rel. column widths of the "P" columns should sum to no more than 0.95.
\hline
\endfirsthead
\hline
\endlastfoot

& Some text here      & \lipsum*[1] \\[1ex]
& Some more text here & \lipsum*[2] \\

\end{longtable}
\endgroup


\begin{center}
\begin{tabular}{@{} N lll @{}}
\hline
& a & b & c \\
& d & e & f \\
\label{row:last}& g & h & i \\
\hline
\end{tabular}
\end{center}

%% Create a cross-reference to the final row:
\noindent
A cross-reference to row \ref{row:last}.
\end{document}
  • Thank you @Mico for the solution, just a clarification, when the text is replaced by \enumerate environment it will create additional vertical space and will not inline with the rest of the items (it only happen if the 3rd column was replaced by \begin{enumerate}) – Bram Setyadji Madusuyatno Feb 24 '18 at 6:14
  • @BramSetyadjiMadusuyatno - I suspect I haven't fully understood what you're trying to achieve. Would you mind editing your posting and stating explicitly what you are looking to do? – Mico Feb 24 '18 at 7:19
  • Nevermind... I've find the solution using \vspace*{-\baselineskip} before \begin{enumerate} :) Sorry for my laziness, Thank you! – Bram Setyadji Madusuyatno Feb 24 '18 at 8:13

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.