3

I want to make tabular. I tried with \makebox[12.5cm] and my code

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{multirow}
\usepackage{longtable,tabularx, makecell}
\begin{document}
\begin{flushleft} 
\makebox[12.5cm][s]{
\begin{tabular}[t]{@{}l@{}}
1.\, Full name \dotfill \\
2.\, Date, month, year born \dotfill \\
3. \, Address \dotfill \\
4. \, Telephont \dotfill \\
  \end{tabular}
  \begin{tabular}[t]{@{}l@{}}
 Donal Mackey \\
 09 - 10 -1972 \\
  New York, U.S.A\\
0123456789\\
  \end{tabular}%
}
\end{flushleft}
\end{document}

I got enter image description here

And with \makebox[8.5cm], I got enter image description here

How Can I make a automatically tabular with change size of \makebox and add order column automatically?

Bernard
  • 271,350

1 Answers1

6

Combining GuM's comment and Herbert's answer on automatic row numbering, one can achieve the following result:

\documentclass[12pt,a4paper]{article}
\usepackage{tabularx}
\usepackage{etoolbox}

\preto\tabular{\setcounter{magicrownumbers}{0}}
\newcounter{magicrownumbers}
\newcommand\rownumber{\stepcounter{magicrownumbers}\arabic{magicrownumbers}}

\begin{document}
\begin{tabularx}{10cm}{@{\makebox[3em][r]{\rownumber.\space}}  X<{\dotfill} @{}l}
  Full name              & Donald Mackey   \\
  Date, month, year born & 09 - 10 -1972   \\
  Adress                 & New York, U.S.A \\
  Telephont              & 0123456789      \\
\end{tabularx}
\end{document}

enter image description here

By replacing 10cm you can set the whole table to any width of your choice. Rows will be automatically numbered and the width of the left column will be automatically filled up with dots.


In order to use the same approach for three columns, where the space between the first and second as well as between the second and third is filled up with dots, you could use the following:

\documentclass[12pt,a4paper]{article}
\usepackage{tabularx}
\usepackage{etoolbox}

\preto\tabular{\setcounter{magicrownumbers}{0}}
\newcounter{magicrownumbers}
\newcommand\rownumber{\stepcounter{magicrownumbers}\arabic{magicrownumbers}}
\begin{document}
\begin{tabularx}{15cm}{@{\makebox[3em][r]{\rownumber.\space}} X<{\dotfill} @{}X <{\dotfill} @{}l } 
  Full name              & Donald Mackey    & some text \\
  Date, month, year born & 09 - 10 -1972    & more text \\
  Adress                 & New York, U.S.A  & entry \\
  Telephont              & 0123456789       & another entry\\
\end{tabularx}
\end{document}

Here, the first and second column are both X type columns which makes them equally wide. If you prefer different widths, you could also use something like \begin{tabularx}{15cm}{@{\makebox[3em][r]{\rownumber.\space}} X<{\dotfill} @{}p{6cm} <{\dotfill} @{}l } and manually determine the desired width of the second column.

leandriis
  • 62,593
  • How can I use your code with ncolumns? – minhthien_2016 Jun 14 '18 at 14:41
  • @minhthien_2016: If you want to add a third column to the table and fill the space between the second and third column with dots, you can add <{\dotfill} @{} just after the column specifier of the second column as well. – leandriis Jun 14 '18 at 15:06
  • @ leandriis I tried `\begin{tabularx}{15cm}{@{\makebox[3em][r]{\rownumber.\space}} X<{\dotfill} @{}l <{\dotfill} @{}l } but I can't the true result. – minhthien_2016 Jun 15 '18 at 05:13
  • @minhthien_2016: I have edited my answer to include an example with three columns. – leandriis Jun 15 '18 at 07:51