Graphics, Figures & TablesWhere to include \caption with \makebox+\tabularx

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
eswap0
Posts: 17
Joined: Tue Sep 28, 2010 8:40 pm

Where to include \caption with \makebox+\tabularx

Post by eswap0 »

Hi,
I am trying to add without success a \caption to the following table, which is included in a \makebox in order to appear in the center and overpassing both margins.

Code: Select all

\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{textcomp}%para monedas
\usepackage[spanish]{babel}
\usepackage[table]{xcolor}
\usepackage{graphicx}
\usepackage{tabularx}
\usepackage{booktabs}

\begin{document}
\noindent\makebox[\textwidth]{
\begin{tabularx}{1.2\linewidth}{lrrrrrr}%\caption{Here comes the caption}
    \addlinespace
    \toprule
    {\bf P\&L S1} & \multicolumn{ 2}{c}{{\bf Comp1}} & \multicolumn{ 2}{c}{{\bf Comp2}} & \multicolumn{ 2}{c}{{\bf Total}} \\
    \midrule
    {\bf } & {\bf £} & {\bf \%} & {\bf £} & {\bf \%} & {\bf £} & {\bf \%} \\
	{\bf Sales} & {\bf 794.249} & {\bf 100,0\%} & {\bf 557.588} & {\bf 100,0\%} & {\bf 1.351.837} & {\bf 100,0\%} \\
    Purchases & 495.198 & 62,3\% & 370.387 & 66,4\% & 865.585 & 64,0\% \\
    {\bf Gross Profit} & {\bf 299.051} & {\bf 37,7\%} & {\bf 187.201} & {\bf 33,6\%} & {\bf 486.252} & {\bf 36,0\%} \\
    \bottomrule
\end{tabularx}}

\end{document}

Any option? Thanks a lot.
Last edited by eswap0 on Sat Oct 09, 2010 2:10 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Where to include \caption with \makebox+\tabularx

Post by localghost »

I see no problem in putting the whole construction into a table environment.

Code: Select all

\documentclass[11pt,a4paper,spanish]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage[font=small,labelfont=bf,tableposition=top]{caption}
\usepackage{booktabs}
\usepackage{textcomp}

\begin{document}
  \begin{table}[!ht]
    \caption{Here comes the caption}\label{tab:money}
    \centering
    \makebox[\textwidth]{%
      \begin{tabular}{lrrrrrr}\toprule
        {\bf P\&L S1} & \multicolumn{2}{c}{{\bf Comp1}} & \multicolumn{2}{c}{{\bf Comp2}} & \multicolumn{2}{c}{{\bf Total}} \\ \midrule
        & {\bf £} & {\bf \%} & {\bf £} & {\bf \%} & {\bf £} & {\bf \%} \\
        {\bf Sales} & {\bf 794.249} & {\bf 100,0\%} & {\bf 557.588} & {\bf 100,0\%} & {\bf 1.351.837} & {\bf 100,0\%} \\
        Purchases & 495.198 & 62,3\% & 370.387 & 66,4\% & 865.585 & 64,0\% \\
    {\bf Gross Profit} & {\bf 299.051} & {\bf 37,7\%} & {\bf 187.201} & {\bf 33,6\%} & {\bf 486.252} & {\bf 36,0\%} \\ \bottomrule
      \end{tabular}
    }
  \end{table}
\end{document}
For font styles you should not use the obsolete LaTeX2.09 syntax.


Thorsten
eswap0
Posts: 17
Joined: Tue Sep 28, 2010 8:40 pm

Re: Where to include \caption with \makebox+\tabularx

Post by eswap0 »

Thank you very much, problem solved.
BTW, I couln't find were I am using obsolete syntax, sorry :oops:
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Where to include \caption with \makebox+\tabularx

Post by localghost »

eswap0 wrote:[…] BTW, I couln't find were I am using obsolete syntax, sorry […]
Following the link regarding font styles would have shown you. \bf is LaTeX2.09 syntax. But we are using LaTeX2e thus switches like \bfseries or declarations like \textbf{bold text} are indicated. Furthermore the LaTeX2.09 syntax has some disadvantages.
eswap0
Posts: 17
Joined: Tue Sep 28, 2010 8:40 pm

Re: Where to include \caption with \makebox+\tabularx

Post by eswap0 »

I see now, thank-you.
It is a pitty, because Exce2LaTeX uses \bf as default.
Used text replace to change {\bf.. to \textbf{...
Thanks
Post Reply