Align minipage on right side
I, in fact, would use a tabular
environment for the title and the text; for the text, a p{<length>}
column (and @{}
to remove the extra space); inside the tabular
, the title can be centered using \multicolumn
:
\documentclass{scrartcl}
\usepackage{showframe}
\usepackage{lipsum}
\begin{document}
\hfill\begin{tabular}{@{}p{.5\linewidth}@{}}
\multicolumn{1}{@{}c@{}}{Some title} \\
\lipsum[4]
\end{tabular}
\end{document}
If this structure will be used several times, an environment can be defined; in the following example, the newly defined myenv
environment has one mandatory argument (the title) and an optional argument (the width used to typeset the text with a default value of 0.5\linewidth
):
\documentclass{scrartcl}
\usepackage{showframe}
\usepackage{lipsum}
\newenvironment{myenv}[2][.5\linewidth]
{\par\hfill\tabular{@{}p{#1}@{}}
\multicolumn{1}{@{}c@{}}{#2} \\ }
{\endtabular\par}
\begin{document}
\begin{myenv}{Some title}
\lipsum*[4]
\end{myenv}
\begin{myenv}[.8\linewidth]{Some title}
\lipsum*[4]
\end{myenv}
\end{document}
If the title spans more than one line, one could load the array
package in the preamble:
\usepackage{array}
and then say
\newenvironment{myenv}[2][.5\linewidth]
{\par\hfill\tabular{@{}p{#1}@{}}
\multicolumn{1}{@{}>{\centering}p{#1}@{}}{#2} \\ }
{\endtabular\par}
You can use 100% plain LaTeX with boxes and the minipage
environment:
with showframe:
without showframe (see example):
Example:
\documentclass{scrartcl}
\usepackage{lipsum}
\begin{document}
\noindent% prevent the box to be shifted a bit to the right
\makebox[\textwidth][r]{% create a box, with it's content aligned to the right
\begin{minipage}{.5\textwidth}% create a content half width
\section{Some title}
\lipsum[4]
\end{minipage}
}
\end{document}