Graphics, Figures & Tablesleftbar environment with table generates error?

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
ptrcao
Posts: 88
Joined: Sun Dec 05, 2010 3:26 am

leftbar environment with table generates error?

Post by ptrcao »

! LaTeX Error: Not in outer par mode.
Minimal example:

Code: Select all

\documentclass[12pt]{article}

\usepackage{booktabs}

\usepackage{framed}


\begin{document}

\begin{leftbar}

\begin{table}[h!]
\centering
\begin{tabular}{l l l l}
\toprule
& black & red & yellow\\
\midrule
expected \% & 70 & 26 & 1\\
observed \% & 64 & 33 & 3\\  
\bottomrule
\end{tabular}
\end{table}


As the cross-tabulation above shows, black was underrepresented by 6\% in the ecologist's captive population, whilst both of red and yellow were overrepresented by 7\% and 2\% respectively, relative to the wild population.
\end{leftbar}

\end{document}
Last edited by ptrcao on Mon Apr 11, 2011 10:25 pm, edited 1 time in total.
OS info: Win XP | Debian 6.0 | Ubuntu 10.04
Latex editor of choice: TexWorks (for dual view feature)

Recommended reading 2024:

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

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

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

leftbar environment with table generates error?

Post by localghost »

[url=http://ctan.org/pkg/framed]framed[/url] package manual wrote:The contents of the framed regions are restricted: Floats, footnotes, margin-
pars and head-line entries will be lost. (Some of these may be handled in a later
version.) This package will not work with the page breaking of multicol, or
other systems that perform column-balancing.
Any questions?


Thorsten
ptrcao
Posts: 88
Joined: Sun Dec 05, 2010 3:26 am

Re: leftbar environment with table generates error?

Post by ptrcao »

Thanks localghost.

So how can I emulate the effect of leftbar, since the environment doesn't seem to support tables?
OS info: Win XP | Debian 6.0 | Ubuntu 10.04
Latex editor of choice: TexWorks (for dual view feature)
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

leftbar environment with table generates error?

Post by localghost »

I see no caption for your table. So why do you need a table environment?
ptrcao
Posts: 88
Joined: Sun Dec 05, 2010 3:26 am

leftbar environment with table generates error?

Post by ptrcao »

localghost wrote:I see no caption for your table. So why do you need a table environment?
Ah, I see your point. :) Usually I find the table environment helps to control the line spacing before and after the table, so for aesthetic reasons, but I guess this could easily be achieved manually?

In this case, you are right, I can forgo the table environment because I'm not using a caption. Elsewhere in the document I'm afraid captions would be used, so it'd still be nice to find a way to make it work...
OS info: Win XP | Debian 6.0 | Ubuntu 10.04
Latex editor of choice: TexWorks (for dual view feature)
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

leftbar environment with table generates error?

Post by localghost »

ptrcao wrote:[…] Usually I find the table environment helps to control the line spacing before and after the table, so for aesthetic reasons, but I guess this could easily be achieved manually? […]
Additional vertical space is not necessary here. The leftbar environment already inserts some space (see code below).
ptrcao wrote:[…] Elsewhere in the document I'm afraid captions would be used, so it'd still be nice to find a way to make it work […]
Take a look at the caption package and its \captionof command (see code sample below).

Code: Select all

\documentclass[12pt,a4paper,english]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage[font=small,labelfont=bf,tableposition=top]{caption}
\usepackage{booktabs,framed}
\usepackage{blindtext}

\begin{document}
  \blindtext
  \begin{leftbar}
    \captionof{table}{Table caption}
    \centerline{%
      \begin{tabular}{lccc}\toprule
        & black & red & yellow\\ \midrule
        expected \% & 70 & 26 & 1 \\
        observed \% & 64 & 33 & 3 \\ \bottomrule
      \end{tabular}
    }

    \bigskip
    As the cross-tabulation above shows, black was underrepresented by 6\% in the ecologist's captive population, whilst both of red and yellow were overrepresented by 7\% and 2\% respectively, relative to the wild population.
  \end{leftbar}
  \blindtext
\end{document}
Although not recommendable, the \centerline command was exceptionally used here to center the table (see l2tabu). Other approaches didn't work properly for me.

As always, the blindtext package is only for creating dummy text thus not part of the solution.
ptrcao
Posts: 88
Joined: Sun Dec 05, 2010 3:26 am

leftbar environment with table generates error?

Post by ptrcao »

localghost wrote:
ptrcao wrote:[…] Usually I find the table environment helps to control the line spacing before and after the table, so for aesthetic reasons, but I guess this could easily be achieved manually? […]
Additional vertical space is not necessary here. The leftbar environment already inserts some space (see code below).
ptrcao wrote:[…] Elsewhere in the document I'm afraid captions would be used, so it'd still be nice to find a way to make it work […]
Take a look at the caption package and its \captionof command (see code sample below).

Code: Select all

\documentclass[12pt,a4paper,english]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage[font=small,labelfont=bf,tableposition=top]{caption}
\usepackage{booktabs,framed}
\usepackage{blindtext}

\begin{document}
  \blindtext
  \begin{leftbar}
    \captionof{table}{Table caption}
    \centerline{%
      \begin{tabular}{lccc}\toprule
        & black & red & yellow\\ \midrule
        expected \% & 70 & 26 & 1 \\
        observed \% & 64 & 33 & 3 \\ \bottomrule
      \end{tabular}
    }

    \bigskip
    As the cross-tabulation above shows, black was underrepresented by 6\% in the ecologist's captive population, whilst both of red and yellow were overrepresented by 7\% and 2\% respectively, relative to the wild population.
  \end{leftbar}
  \blindtext
\end{document}
Although not recommendable, the \centerline command was exceptionally used here to center the table (see l2tabu). Other approaches didn't work properly for me.

As always, the blindtext package is only for creating dummy text thus not part of the solution.
Very good; it works, though not ideal as you point out. :)

Q: I noticed the commenting out immediately after "\centerline{" was necessary or else \centerline is inappropriately applied to the text after the table as well. Why does that happen? Thanks.
OS info: Win XP | Debian 6.0 | Ubuntu 10.04
Latex editor of choice: TexWorks (for dual view feature)
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

leftbar environment with table generates error?

Post by localghost »

ptrcao wrote:[…] it works, though not ideal as you point out. […]
Where did I say that. The table is centered properly.
ptrcao wrote:[…] I noticed the commenting out immediately after "\centerline{" was necessary or else \centerline is inappropriately applied to the text after the table as well. Why does that happen? […]
In some cases the „%“ character affects the following code (detailed explanation in „The TeXbook“). But not here, where it was only used for security precaution to avoid spaces (usually helpful in macro definitions). The output is the same with or without it
ptrcao
Posts: 88
Joined: Sun Dec 05, 2010 3:26 am

leftbar environment with table generates error?

Post by ptrcao »

localghost wrote:
ptrcao wrote:[…] it works, though not ideal as you point out. […]
Where did I say that. The table is centered properly.
Yes, you are right; I only meant un-ideal in the sense that the use of \centerline is discouraged. But that's ok; we do what we have to to make it work.
localghost wrote: The output is the same with or without it
Yes, I can confirm that. The difference I was talking about was actually due to me changing \centering to \centerline, and not by adding/removing "%".

My mistake, and thanks again Thorsten, the solution is perfectly sufficient.
OS info: Win XP | Debian 6.0 | Ubuntu 10.04
Latex editor of choice: TexWorks (for dual view feature)
Post Reply