2

I am using multicolum under tabularx a lot. Instead of removing spaces

\multicolumn{2}{@{}l}{...}

I want to create a new environment which removes trailing spaces from both front and end. Any suggestions on doing the same? Thanks.

Regards,

Edit :

When I use the following piece of code,

\begin{tabularx}{\textwidth}{@{}Xc@{}}
\toprule\toprule
Some random text & 1,75,650\\\midrule
\multicolumn{2}{@{}l}{\textbf{Panel A1: AAA}} \\\midrule
Number of observations ... & 1,75,650\\

I get enter image description here

But if I use (@{} removed from multicloumn)

\begin{tabularx}{\textwidth}{@{}Xc@{}}
\toprule\toprule
Some random text & 1,75,650\\\midrule
\multicolumn{2}{l}{\textbf{Panel A1: AAA}} \\\midrule
Number of observations ... & 1,75,650\\

I get enter image description here

As I would have to use \multicolumn{2}{@{}l} multiple times, hence I was looking to create a new env. which takes care of @{}.

In case someone is looking for MWE:

\documentclass{article}
\usepackage{ltablex}
\usepackage{threeparttable}
\usepackage{booktabs}

\title{Document}
\begin{document}
\maketitle

\begin{tabularx}{\textwidth}{Xc}
\toprule\toprule
Some random text & 1,75,650\\\midrule
\multicolumn{2}{l}{\textbf{Panel A1: AAA}} \\\midrule
Number of observations ... & 1,75,650\\
Delete: ... & (78,420)\\
Delete: ... & (7,104)\\
Final sample & 90,126\\
Delete: & (2,143)\\
Delete: & (8,345)\\
Final sample & 79,638\\\midrule
\multicolumn{2}{l}{\textbf{Panel A2: AAA}} \\\midrule
Number of observations & 79,638\\
Delete: & (39,540)\\
Delete: & (7,979) \\
Final sample & 32,119 \\\midrule
\multicolumn{2}{l}{\textbf{Panel B1: BBB }} \\\midrule
Number of observations  & 1,75,650\\
Delete: & (78,420)\\
Delete: & (47,136)\\
Delete: & (7,178)\\
Delete: & (32)\\
Delete: & (32)\\
Delete: & (32)\\
Delete: & (32)\\
Delete: & (32)\\
Delete: & (32)\\
Delete: & (32)\\
Delete: & (32)\\
Final sample & 42,884\\\midrule
\multicolumn{2}{l}{\textbf{Panel B2: BBB}} \\\midrule
Number of observations  & 1,75,650\\
Delete: & (78,420)\\
Delete: & (47,136)\\
Delete: & (7,178)\\
Delete: & (32)\\
Delete: & (32)\\
Delete: & (32)\\
Delete: & (32)\\
Delete: & (32)\\
Delete: & (32)\\
Delete: & (32)\\
Delete: & (32)\\
Number of observations  & 1,75,650\\
Delete: & (78,420)\\
Delete: & (47,136)\\
Delete: & (7,178)\\
Delete: & (32)\\
Delete: & (32)\\
Delete: & (32)\\
Delete: & (32)\\
Delete: & (32)\\
Delete: & (32)\\
Delete: & (32)\\
Delete: & (32)\\
Final sample & 42,884\\\midrule\bottomrule
\end{tabularx}

\end{document}

Edit: In case, someone might be interested, this is how I defined:

\newcommand{\gmc}[2]{\multicolumn{#1}{@{}#2@{}}}
6
  • multicolumn already trims space, perhaps you are looking to remove the padding around the table in which case you want \begin{tabularx}{\textwidth}{@{}Xc@{}} (although as each cell entry is a single line, you shouldn't be using tabularx here really) Mar 24, 2014 at 9:56
  • Which I see is exactly the answer you got to tex.stackexchange.com/questions/167368/hfill-not-working Mar 24, 2014 at 10:02
  • @DavidCarlisle have a look at the edits I made. Also, I am using tabularx as the table is long, also multiple cell entries are more than one line, which I have not shown in MWE for brevity.
    – Sumit
    Mar 24, 2014 at 10:20
  • \newcommand{\tmc}[1]{\multicolumn{1}{@{}#1}} and then \tmc{l} will do.
    – egreg
    Mar 24, 2014 at 10:32
  • @egreg doesn't work for me. I guess this is because of \multicolumn{1}{@{}#1}, what if I use \tmc{l} as a replacement of \multicolumn{2}{@{}l}?
    – Sumit
    Mar 24, 2014 at 10:41

1 Answer 1

1

An example with tabularray and a new table command \gmc:

\documentclass[twocolumn]{article}

\usepackage{tabularray}
\UseTblrLibrary{booktabs}

\NewTableCommand{\gmc}{\SetCell[c=2]{l}\SetRow{font=\bfseries}}

\DefTblrTemplate{contfoot-text}{default}{To be continued}
\DefTblrTemplate{conthead-text}{default}{(continued)}

\title{Document}
\author{}

\begin{document}

\maketitle

\begin{longtblr}[
    caption={A table \emph{without} initial and final space before the columns}
    ]{
    colspec={Xc},
    column{1}={leftsep=0pt},
    column{Z}={rightsep=0pt},
    }
\toprule\toprule
Some random text & 1,75,650\\\midrule
\gmc Panel A1: AAA \\\midrule
Number of observations ... & 1,75,650\\
Delete: ... & (78,420)\\
Delete: ... & (7,104)\\
Final sample & 90,126\\
Delete: & (2,143)\\
Delete: & (8,345)\\
Final sample & 79,638\\\midrule
\gmc Panel A2: AAA \\\midrule
Number of observations & 79,638\\
Delete: & (39,540)\\
Delete: & (7,979) \\
Final sample & 32,119 \\\midrule
\gmc Panel B1: BBB \\\midrule
Number of observations  & 1,75,650\\
Delete: & (78,420)\\
Delete: & (47,136)\\
Delete: & (7,178)\\
Delete: & (32)\\
Delete: & (32)\\
Delete: & (32)\\
Delete: & (32)\\
Delete: & (32)\\
Delete: & (32)\\
Delete: & (32)\\
Delete: & (32)\\
Final sample & 42,884\\\midrule
\gmc Panel B2: BBB\\\midrule
Number of observations  & 1,75,650\\
Delete: & (78,420)\\
Delete: & (47,136)\\
Delete: & (7,178)\\
Delete: & (32)\\
Delete: & (32)\\
Delete: & (32)\\
Delete: & (32)\\
Delete: & (32)\\
Delete: & (32)\\
Delete: & (32)\\
Delete: & (32)\\
Number of observations  & 1,75,650\\
Delete: & (78,420)\\
Delete: & (47,136)\\
Delete: & (7,178)\\
Delete: & (32)\\
Delete: & (32)\\
Delete: & (32)\\
Delete: & (32)\\
Delete: & (32)\\
Delete: & (32)\\
Delete: & (32)\\
Delete: & (32)\\
Final sample & 42,884\\\midrule\bottomrule
\end{longtblr}

\begin{longtblr}[
    caption={A table \emph{with} initial and final space before the columns}
    ]{
    colspec={Xc}
    }
\toprule\toprule
Some random text & 1,75,650\\\midrule
\gmc Panel A1: AAA \\\midrule
Number of observations ... & 1,75,650\\
Delete: ... & (78,420)\\
Delete: ... & (7,104)\\
Final sample & 90,126\\
Delete: & (2,143)\\
Delete: & (8,345)\\
Final sample & 79,638\\\midrule
\gmc Panel A2: AAA \\\midrule
Number of observations & 79,638\\
Delete: & (39,540)\\
Delete: & (7,979) \\
Final sample & 32,119 \\\midrule
\gmc Panel B1: BBB \\\midrule
Number of observations  & 1,75,650\\
Delete: & (78,420)\\
Delete: & (47,136)\\
Delete: & (7,178)\\
Delete: & (32)\\
Delete: & (32)\\
Delete: & (32)\\
Delete: & (32)\\
Delete: & (32)\\
Delete: & (32)\\
Delete: & (32)\\
Delete: & (32)\\
Final sample & 42,884\\\midrule
\gmc Panel B2: BBB\\\midrule
Number of observations  & 1,75,650\\
Delete: & (78,420)\\
Delete: & (47,136)\\
Delete: & (7,178)\\
Delete: & (32)\\
Delete: & (32)\\
Delete: & (32)\\
Delete: & (32)\\
Delete: & (32)\\
Delete: & (32)\\
Delete: & (32)\\
Delete: & (32)\\
Number of observations  & 1,75,650\\
Delete: & (78,420)\\
Delete: & (47,136)\\
Delete: & (7,178)\\
Delete: & (32)\\
Delete: & (32)\\
Delete: & (32)\\
Delete: & (32)\\
Delete: & (32)\\
Delete: & (32)\\
Delete: & (32)\\
Delete: & (32)\\
Final sample & 42,884\\\midrule\bottomrule
\end{longtblr}
\end{document}

enter image description here

enter image description here

Off-topic: your number 1,75,650 is quite strange.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .