LaTeX forum ⇒ Generalquestion: how to align left and align right in same line

LaTeX specific issues not fitting into one of the other forums of this category.
anonymous188
Posts: 3
Joined: Sat Oct 25, 2008 12:28 am

question: how to align left and align right in same line

Postby anonymous188 » Sat Oct 25, 2008 12:48 am

Hey everyone,

I have to prepare a report using a specific format, of which I attached an image (1). The only problem is I don't know how to:

1. Align two items on the same line, one left one right
2. Make them both appear the same as a \section{} or \subsection{} header.

The best attempt I've had was the following code:

  1. \begin{minipage}{0.5\textwidth}
  2. \begin{flushleft}
  3. \subsection*{Alex W}
  4. \end{flushleft}
  5. \end{minipage}
  6. \begin{minipage}{0.5\textwidth}
  7. \begin{flushright}
  8. \textbf{\large October 24, 2008}\\[1.5cm]
  9. \end{flushright}
  10. \end{minipage}
  11. \\
  12. \subsection*{Bahaa B}


which has its output shown in the second picture. As you can see, my name isn't quite justified all the way to the left. Any help would be appreciated. :)

Thanks,

Alex W.

lab_report_format_copy.jpg
Note that Name and Date are aligned left and right, respectively, on the same line.
lab_report_format_copy.jpg (54.56 KiB) Viewed 145197 times

example copy.jpg
My output.
example copy.jpg (15.09 KiB) Viewed 145201 times

Link:
BBcode:
HTML:
Hide post links
Show post links

User avatar
Stefan Kottwitz
Site Admin
Posts: 7801
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:

Postby Stefan Kottwitz » Sat Oct 25, 2008 1:04 am

Hi Alex,

welcome to the board!
Just insert \hfill, for example:
  1. Left aligned text\hfill right aligned text

Stefan
Site admin

Link:
BBcode:
HTML:
Hide post links
Show post links

anonymous188
Posts: 3
Joined: Sat Oct 25, 2008 12:28 am

Postby anonymous188 » Sat Oct 25, 2008 1:49 am

Thanks for the reply. :) When I insert \hfill between the two texts, like so:

  1. \begin{minipage}{0.5\textwidth}
  2. \begin{flushleft}
  3. \subsection*{Alex W}
  4. \end{flushleft}
  5. \end{minipage}
  6. \hfill
  7. \begin{minipage}{0.5\textwidth}
  8. \begin{flushright}
  9. \textbf{\large October 24, 2008}\\[1.5cm]
  10. \end{flushright}
  11. \end{minipage}
  12. \\
  13. \subsection*{Bahaa B}


I get the same result as last time. I experimented by putting the command in various places wrt the two, but I don't think it's solving the problem. Correct me if I'm wrong, but I'm assuming \hfill lets the date go all the way to the end (horizontally). If that's the case, then I don't know if it would help align my name all the way to the left.

Thanks again for any help clarifying this.

Regards,

Alex W.

Link:
BBcode:
HTML:
Hide post links
Show post links

User avatar
Stefan Kottwitz
Site Admin
Posts: 7801
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:

Postby Stefan Kottwitz » Sat Oct 25, 2008 3:27 am

Hi Alex,

that's caused by the paragraph indentation, insert \noindent before the first minipage:
  1. \noindent\begin{minipage}{0.5\textwidth}
  2. ...

Note that those two minipages will extend \textwidth, because there will be a small space between the two minipages, I would make them smaller.

Stefan
Site admin

Link:
BBcode:
HTML:
Hide post links
Show post links

User avatar
Juanjo
Posts: 656
Joined: Sat Jan 27, 2007 12:46 am

Postby Juanjo » Sat Oct 25, 2008 3:29 am

What about this?
  1. \noindent{\bfseries\large Alex W\hfill October 24, 2008}
  2.  
  3. \subsection*{Bahaa B}
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.

Link:
BBcode:
HTML:
Hide post links
Show post links

anonymous188
Posts: 3
Joined: Sat Oct 25, 2008 12:28 am

Postby anonymous188 » Sat Oct 25, 2008 4:07 am

Perfect! Thanks for your help guys.

-Alex W.

Link:
BBcode:
HTML:
Hide post links
Show post links


Return to “General”

Who is online

Users browsing this forum: Bing [Bot] and 8 guests