# New column type tabularx

I try to make a table with \newcolumntype. I am aware that the code as it is, is not working and not correctly used for the purpose I have.

My goal is to make a table with two colums (each column of the same size). => The table should look similar to the pic under the code but with the columns of the same width

Could you help me?

% page setup
\documentclass[a4paper, 11pt]{article}
\usepackage[left=3cm,top=3cm,right=3cm]{geometry}
\usepackage{fancyvrb}

% tables
\usepackage{ragged2e}
\usepackage{booktabs, tabularx}
\newcolumntype{P}[2]{>{\RaggedRight\hspace{0pt}}m{#1}}

\begin{document}
\begin{table}[ht]
\settowidth\colwidth{Ion-exchange chroma} % both boxes should have same with
\begin{tabularx}{\textwidth}{@{} P{\colwidth} }
\toprule
Native Gel & Denatured Gel  \\
\midrule
\begin{itemize}
\item   separation upon ---
\end{itemize} &
\begin{itemize}
\item   separation upon ---
\end{itemize}        \\

\bottomrule
\end{tabularx}
\end{table}

\end{document}



• I am very much aware of the mistake and the wrong using. I tried to make my request not contradictory. Unfortunately I am just a beginner.
– Elia
Dec 10, 2020 at 11:07
• Why are you definint P to take two arguments when you only use one (#1) additionally good idea to use \RaggedRight\arraybackslash otherwise \\ might not work correctly Dec 10, 2020 at 11:16
• Where is \colwidth defined? Dec 10, 2020 at 11:17

• The code requires a \newlength\colwidth declaration in the preamble.

• \newcolumntype{P}[2]{>{\RaggedRight\hspace{0pt}}m{#1}} has to be changed to

\newcolumntype{P}[1]{>{\RaggedRight\hspace{0pt}}m{#1}}

• Since there two columns in the tabularx environment,

\begin{tabularx}{\textwidth}{@{} P{\colwidth} }


has to be changed to

\begin{tabularx}{\textwidth}{@{} *{2}{P{\colwidth}}}


Of course, "getting the code to compile" doesn't imply that your code does what you intend it to do. For instance, since the code doesn't contain any X-type columns, no useful purpose is served by employing a tabularx environment. I suggest you use a basic tabular environment instead. On the other hand, if you really do wish to employ a tabularx environment, you needn't set up the P column type; instead use the X column type.

The following screenshot is the result of applying the prececing suggestions. The upper table employs a tabular environment, the lower one uses a tabularx environment.

\documentclass[a4paper, 11pt]{article}
\usepackage[hmargin=3cm,top=3cm]{geometry}
\usepackage{fancyvrb}

% tables
\usepackage{ragged2e}
\usepackage{booktabs, tabularx}

\newcolumntype{P}[1]{>{\RaggedRight\hspace{0pt}}m{#1}}
\newcolumntype{L}{>{\RaggedRight\hspace{0pt}}X}
\renewcommand{\tabularxcolumn}[1]{m{#1}}

\newlength\colwidth
\settowidth\colwidth{Ion-exchange chroma}  % measure intended width of 'P' columns

\begin{document}
\begin{table}[ht]
\centering

\caption{Using a \texttt{tabular} env.\ and the \texttt{P} col.\ type\strut}
\begin{tabular}{@{} *{2}{P{\colwidth}} @{} }
\toprule
Native Gel & Denatured Gel  \\
\midrule
\begin{itemize}
\item   separation upon ---
\end{itemize} &
\begin{itemize}
\item   separation upon ---
\end{itemize}        \\
\bottomrule
\end{tabular}

\hspace{1cm}

\caption{Using a \texttt{tabularx} env.\ and the \texttt{L} col. type\strut}
\begin{tabularx}{\textwidth}{@{} LL @{} }
\toprule
Native Gel & Denatured Gel  \\
\midrule
\begin{itemize}
\item   separation upon ---
\end{itemize} &
\begin{itemize}
\item   separation upon ---
\end{itemize}        \\
\bottomrule
\end{tabularx}
\end{table}

\end{document}

• Thank you for your your adjustments to the code. It compiles but I get en error that the \colwidth has already be defined and I don't get two colums of the same size just one column and the text is overlaying
– Elia
Dec 10, 2020 at 11:30
• @ella - If I apply the three adjustments stated above to the code you provided in your posting, the code compiles. If they don't work for you, the only explanation is that your code is not the same as what you posted. I such a case, all bets are most certainly off.
– Mico
Dec 10, 2020 at 11:32
• I am sorry then than am not able to do it - never mind
– Elia
Dec 10, 2020 at 11:33
• @Elia - I've updated the answer to incorporate the additional information you provided in the revised query.
– Mico
Dec 10, 2020 at 11:51
1. make sure \colwidth is defined

2. Define P properly

 \newcolumntype{P}[1]{%
>{\RaggedRight\arraybackslash\hspace{0pt}}m{#1}
>{\RaggedRight\arraybackslash\hspace{0pt}}m{#1}
}


Then it seems to compile. Though your example does not make much sense as you are not using any X columnsm, so what is the point of using tabularx here?