# Using an environment leaves a line by default.

#### caffeinemachine

##### Well-known member
MHB Math Scholar
Suppose in LaTeX I write:

This the first line. begin{center}This is the centered line. end{center}.

What I get is:

This is the first line

This is the centered line.

But suppose I want this:

This is the first line.~~~~~~~~~~~~~~~~This is the centered line.

(Here tilde is white space. Some how simply using spacebar wasn't working.)

What is the way to do it? My problem is that when I open any environment a fixed amount of space is always left before and after the contents of the contents of the environment. How can I control the amount of space left?

#### Ackbach

##### Indicium Physicus
Staff member
Well, \hspace is one way. You could write

Code:
This is the first line. $\hspace{3in}$ This is the centered line.
producing

This is the first line. $\hspace{3in}$ This is the centered line.

Then you could play around with the spacing command. It's a rather bone-headed way to do it, but also quick and dirty. It almost looks like you're wanting a two-column environment. Is that the case?

#### Opalg

##### MHB Oldtimer
Staff member
Suppose in LaTeX I write:

This the first line. begin{center}This is the centered line. end{center}.

What I get is:

This is the first line

This is the centered line.

But suppose I want this:

This is the first line.~~~~~~~~~~~~~~~~This is the centered line.

(Here tilde is white space. Some how simply using spacebar wasn't working.)

What is the way to do it? My problem is that when I open any environment a fixed amount of space is always left before and after the contents of the contents of the environment. How can I control the amount of space left?
One way to do this would be to go back to basics, and use the plain TeX spacing commands instead of the LaTeX center environment.

It's not clear to me whether you want "This is the centered line" to have a line to itself, but without the extra spacing above and below that the center environment provides, or whether you actually want "This is the centered line" to be on the same line as "This is the first line."

If it is to have a line to itself, that is easily done as follows:
Code:
This is the first line. \\
\hspace*{\fill} This is the centered line. \hspace*{\fill} \\
This is the next line.
That will give:

This is the first line.
This is the centered line.​
This is the next line.

But if you want both things to be on the same line, there is then a further question. Do you want "This is the centered line" to be centred on the whole line, or do you want it to be centred in the part of the line to the right of "This is the first line"? In the first case, you need this:
Code:
\leavevmode
\rlap{This is the first line.} \hfill This is the centered line. \hspace*{\fill} \\
This is the next line.
In the second case, you need this:
Code:
This is the first line. \hfill This is the centered line. \hspace*{\fill} \\
This is the next line.
The outcomes from those will look something like this:
Code:
This is the first line.[COLOR=beige]............[/COLOR]This is the centered line.[COLOR=beige]....................................[/COLOR]|
This is the next line.[COLOR=beige]...........................................................................[/COLOR]|
[COLOR=beige]........................................................................                      ...[/COLOR]|
[COLOR=beige]........................................................................                      ...[/COLOR]|
[COLOR=beige]........................................................................                      ...[/COLOR]|
This is the first line.[COLOR=beige]....            ........[/COLOR]This is the centered line.[COLOR=beige]........................[/COLOR]|
This is the next line.[COLOR=beige]...........................................................................[/COLOR]|
(the bar denotes where the right margin starts).

#### caffeinemachine

##### Well-known member
MHB Math Scholar
One way to do this would be to go back to basics, and use the plain TeX spacing commands instead of the LaTeX center environment.

It's not clear to me whether you want "This is the centered line" to have a line to itself, but without the extra spacing above and below that the center environment provides, or whether you actually want "This is the centered line" to be on the same line as "This is the first line."

If it is to have a line to itself, that is easily done as follows:
Code:
This is the first line. \\
\hspace*{\fill} This is the centered line. \hspace*{\fill} \\
This is the next line.
That will give:

This is the first line.
This is the centered line.​
This is the next line.

But if you want both things to be on the same line, there is then a further question. Do you want "This is the centered line" to be centred on the whole line, or do you want it to be centred in the part of the line to the right of "This is the first line"? In the first case, you need this:
Code:
\leavevmode
\rlap{This is the first line.} \hfill This is the centered line. \hspace*{\fill} \\
This is the next line.
In the second case, you need this:
Code:
This is the first line. \hfill This is the centered line. \hspace*{\fill} \\
This is the next line.
The outcomes from those will look something like this:
Code:
This is the first line.[COLOR=beige]............[/COLOR]This is the centered line.[COLOR=beige]....................................[/COLOR]|
This is the next line.[COLOR=beige]...........................................................................[/COLOR]|
[COLOR=beige]........................................................................                      ...[/COLOR]|
[COLOR=beige]........................................................................                      ...[/COLOR]|
[COLOR=beige]........................................................................                      ...[/COLOR]|
This is the first line.[COLOR=beige]....            ........[/COLOR]This is the centered line.[COLOR=beige]........................[/COLOR]|
This is the next line.[COLOR=beige]...........................................................................[/COLOR]|
(the bar denotes where the right margin starts).