1

I need to center the table but I am forced to use the following macro:

\def\tbl#1#2#3{%
\global\setbox\tabcapbox\vbox{#1}%
\global\setbox\tabbox\hbox{#2}%
\global\setbox\tabnotebox\vbox{#3}%
\noindent\vbox{%
\tablemove\textwidth%
\advance\tablemove-\wd\tabbox%
\divide\tablemove2%
%\hspace*{\tablemove}
\vbox{%
\hsize\wd\tabbox%
#1%
#2%
#3}}}

The macro do not allow me to center the table. I used \centering and it did not work (not exactly center). I used makebox[\textwidth][c]{ around the tabular but not exactly centered. What modifications (or deletion) I need to do in the macro to get the whole table centered.

Here is the whole code snippets:

\documentclass{article}
%\usepackage{chngcntr}
\usepackage{amsmath}
\usepackage{multirow}
\usepackage{graphicx}
\usepackage{natbib}
\usepackage[hidelinks,colorlinks=true,linkcolor=blue,citecolor=blue,urlcolor=blue]{hyperref} % to include link for every
%\usepackage{hyperref}
\usepackage[extra]{tipa}
\usepackage{blindtext}

\ifpdf%
\usepackage{epstopdf}%
\else%
\fi

\makeatletter
\newbox\tabcapbox
\newbox\tabbox
\newbox\tabnotebox
\newdimen\tablemove
\newdimen\sidetskip\sidetskip=0pt%
\newdimen\sideverticalskip\sideverticalskip=0pt
\newif\ifUnNumtable\global\UnNumtablefalse
\newskip\tablenumcapsep
\newif\ifUnNumtable\global\UnNumtablefalse

\renewcommand{\sfdefault}{phv}%

\newenvironment{tabnote}{\@par\tabnotefont\vphantom{y}\vskip-1pt}
    {\@par}

\def\tablefont{\fontfamily{\sfdefault}\fontsize{7.75}{9}\selectfont}%
\def\tablecaptionfont{\fontfamily{\sfdefault}\fontsize{7.75}{9}\selectfont}%
\def\tablecaptwofont{\fontfamily{\sfdefault}\fontsize{7.8}{9}\selectfont}%
\def\tablecaptionnumfont{\fontsize{7.75}{9}\fontfamily{\sfdefault}\fontseries{sb}\fontshape{n}\selectfont}%
\def\TCHfont{\fontfamily{\sfdefault}\fontsize{7.5}{9}\selectfont}%
\def\TSCHfont{}%
\def\tabnotefont{\fontfamily{\sfdefault}\fontsize{6.51}{8}\selectfont}% use plus 1fill if needed
%% Long-Table
\def\LTtablecaptionfont{\fontfamily{\sfdefault}\fontsize{7.5}{9}\selectfont}%
\def\LTtablenotefont{\fontfamily{\sfdefault}\fontsize{7.5}{9}\selectfont}%




\def\tbl#1#2#3{%
\global\setbox\tabcapbox\vbox{#1}%
\addtocounter{table}{-1}%
\global\setbox\tabbox\hbox{#2}%
\global\setbox\tabnotebox\vbox{#3}%
\noindent\vbox{%
\tablemove\textwidth%
\advance\tablemove-\wd\tabbox%
\divide\tablemove2%
%\hspace*{\tablemove}
\vbox{%
\hsize\wd\tabbox%
#1%
#2%
#3}}}

\def\@maketablecaption#1#2{
\setbox\tabcapbox\vbox{{\tablecaptionfont\ifunnumtable\else\noindent{\tablecaptionnumfont#1}\fi{\tablecaptionnumfont}\hskip\tablenumcapsep#2\vphantom{y}\par}}
%\ifdim\wd\tabcapbox<\textwidth
\ifdim\ht\tabcapbox<19pt
%\centerlast
{\tablecaptionfont\ifunnumtable\else\noindent{\tablecaptionnumfont#1}\fi{\tablecaptionnumfont}\hskip\tablenumcapsep#2\vphantom{y}\vskip.8pt}\global\unnumtablefalse%
\else
{\tablecaptionfont\ifunnumtable\else\noindent{\tablecaptionnumfont#1}\fi{\tablecaptionnumfont}\hskip\tablenumcapsep#2\vphantom{y}\vskip.8pt}\global\unnumtablefalse%
\fi}

\begin{document}

\blindtext

\begin{table}[h!]

  \tbl{\caption{\label{tab:ArabicDialects} Arabic dialects covered in our study.}}
 {\begin{minipage}{25pc}
 \makebox[\textwidth][c]{
    \begin{tabular}{@{\extracolsep{\fill}}p{0.25\textwidth}p{0.21\textwidth}}
    \hline
    Arabic dialect & Abbreviation \\
    \hline
     Apple & 12  \\
     Android  &  20\\
     Swift &  33\\
     Google &  11\\
     Yahoo &  11\\
     Altavista &  23\\
     HP &  45\\
    \hline
    \end{tabular}}
  \end{minipage}}
  {\begin{tabnote}
  \end{tabnote}}
\end{table}


\end{document}

the \tbl macro is part of the journal class. Only change \documentclass{article} to \documentclass{Jclass}. You may face problems as the class is not compatible with recent LaTeX 2e-kernels but can be solved as explained here.

7
  • What is the purpose of \tbl here? – leandriis Mar 13 at 12:43
  • 1
    You are making a minipage of 25pc width so that'll never be centered. Just use \begin{minipage}{\linewidth}\centering\begin{tabular}...\end{tabular}\end{minipage}. – campa Mar 13 at 12:45
  • 1
    unrelated but you probably want to remove \ifpdf% \usepackage{epstopdf}% \else% \fi – David Carlisle Mar 13 at 13:00
  • the \tbl macro is low level primitive tex code that should never be in a latex document, what is "forcing" you to use it? the \makebox is off-center as you are adding space before the tabular and not after it, the space coming from the newline here \makebox[\textwidth][c]{ – David Carlisle Mar 13 at 13:03
  • I tried to make things easier! I need to use \tbl macro as it is part of a journal class but many who tried this journal class face problem with it especially if they have a newer version or updated packages. Therefore, I decided to give only a code snippet. I will update the question to refer to that journal class. – Wahedsaw Mar 13 at 13:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.