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.
Post Reply
anonymous188
Posts: 3
Joined: Sat Oct 25, 2008 12:28 am

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

Post by anonymous188 »

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:

Code: Select all

\begin{minipage}{0.5\textwidth}
\begin{flushleft}
    \subsection*{Alex W}
\end{flushleft}
\end{minipage}
\begin{minipage}{0.5\textwidth}
\begin{flushright}
    \textbf{\large October 24, 2008}\\[1.5cm]
\end{flushright}
\end{minipage}
\\
\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.
Note that Name and Date are aligned left and right, respectively, on the same line.
Note that Name and Date are aligned left and right, respectively, on the same line.
lab_report_format_copy.jpg (54.56 KiB) Viewed 213029 times
My output.
My output.
example copy.jpg (15.09 KiB) Viewed 213033 times

Recommended reading 2024:

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

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

Stefan Kottwitz
Site Admin
Posts: 10347
Joined: Mon Mar 10, 2008 9:44 pm

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

Post by Stefan Kottwitz »

Hi Alex,

welcome to the board!
Just insert \hfill, for example:

Code: Select all

Left aligned text\hfill right aligned text
Stefan
LaTeX.org admin
anonymous188
Posts: 3
Joined: Sat Oct 25, 2008 12:28 am

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

Post by anonymous188 »

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

Code: Select all

\begin{minipage}{0.5\textwidth}
\begin{flushleft}
    \subsection*{Alex W}
\end{flushleft}
\end{minipage}
\hfill
\begin{minipage}{0.5\textwidth}
\begin{flushright}
    \textbf{\large October 24, 2008}\\[1.5cm]
\end{flushright}
\end{minipage}
\\
\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.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10347
Joined: Mon Mar 10, 2008 9:44 pm

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

Post by Stefan Kottwitz »

Hi Alex,

that's caused by the paragraph indentation, insert \noindent before the first minipage:

Code: Select all

\noindent\begin{minipage}{0.5\textwidth}
...
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
LaTeX.org admin
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

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

Post by Juanjo »

What about this?

Code: Select all

\noindent{\bfseries\large Alex W\hfill October 24, 2008}

\subsection*{Bahaa B}
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
anonymous188
Posts: 3
Joined: Sat Oct 25, 2008 12:28 am

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

Post by anonymous188 »

Perfect! Thanks for your help guys.

-Alex W.
Post Reply