GeneralA question about columns

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
habib_seif
Posts: 5
Joined: Sun Nov 08, 2009 5:59 pm

A question about columns

Post by habib_seif »

Dear friends,

Is there any environment for setting number of columns to one?

As you know \onecolumn can set number of columns to one, but it's a command not environment. Therefore, I can't set number of columns to what it was before the \onecolumn.... I would like to have an environment like:

\begin{onecolumn}
...
text
...
\end{onecolumn}

I also tried \begin{multicols}{1} ... \end{multicols}{1} but it sounds that multicol package requires a number more than 1.

Thanks a lot,
Habib

Recommended reading 2024:

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

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

frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

A question about columns

Post by frabjous »

habib_seif wrote:Dear friends,

I also tried \begin{multicols}{1} ... \end{multicols}{1} but it sounds that multicol package requires a number more than 1.
I don't understand the problem. Everything not in such an environment will be in one column. You only need to use the multicol environment if you want more than one.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

A question about columns

Post by localghost »

frabjous wrote:I don't understand the problem. Everything not in such an environment will be in one column. You only need to use the multicol environment if you want more than one.
I think guess that habib_seif has set the twocolumn option for the document class and now wants to switch to one column temporarily.


Best regards
Thorsten
habib_seif
Posts: 5
Joined: Sun Nov 08, 2009 5:59 pm

Re: A question about columns

Post by habib_seif »

OK, let me explain what I exactly want to do...

I'm writing a paper which its class has not been determined yet: IEEE, ACM, Springer, .... So I don't know that if the whole paper is one columned or two columned and I don't want to change overall style since it has been set by the class. But I just would like to temporarily set the style to one column and then set back the number of columns to what it was before.

I hope that's enough to explains

By the way, I'm sure that LaTeX has commands to check conditions, set variables and ... like any other programming language. If there are commands for saving number of columns into a variable please let me know.

Cheers,
Habib
phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

A question about columns

Post by phi »

The standard classes commonly use the switches \if@twocolumn and \if@restonecoltrue for this. Here is a possibility with a custom switch:

Code: Select all

\newcommand*{\restorecolumns}{}
\makeatletter
\newenvironment*{OneColumn}{%
  \if@twocolumn
    \let\restorecolumns\twocolumn
  \else
    \let\restorecolumns\@empty
  \fi
  \onecolumn
  \ignorespaces
}{%
  \restorecolumns
  \ignorespacesafterend
}
\makeatother
habib_seif
Posts: 5
Joined: Sun Nov 08, 2009 5:59 pm

Re: A question about columns

Post by habib_seif »

Dear phi,

The code you proposed worked great for me. Thanks a lot...

But some other questions:

1- The first and most important one is that is there any reference or book that lists the most important commands (like \if@twocolumn) and explains how we can use them? I'm newbie, so what's the start point?
2- the newly defined {OneColumn} environment breaks the page even if the number of columns was one from the begining. How we can avoid this? (Excuse me for such newbie questions... I'm sure that it can be easily done by adding a command to if condition)
3- If the style is twocolumn and we use {OneColumn} environment, the last page of twocolumns is not balanced. How can I do that?

If any hercule guy answers my first question, I will try to find answer of other questions by myself.

Anyway, thanks a lot for solving my problem.

Cheers,
Habib
habib_seif
Posts: 5
Joined: Sun Nov 08, 2009 5:59 pm

A question about columns

Post by habib_seif »

I finally found the answers of question 2 and 3. Here is the code for solving the problems:

Code: Select all

\newcommand*{\restorecolumns}{}
\makeatletter
\newenvironment*{OneColumn}{%
	\if@twocolumn
		\balance
		\let\restorecolumns\twocolumn
		\onecolumn
	\else
		\let\restorecolumns\@empty
	\fi
	\ignorespaces
}{%
	\nobalance	
	\restorecolumns
	\ignorespacesafterend
}
\makeatother
Any link to LaTeX internal commands is greatly appreciated...

Cheers,
Habib
Post Reply