[Tex/LaTex] Alignment inside minipage with flushright

indentationminipage

Please help me to figure out how to produce with that:

I have the following code:

\begin{flushright}
\begin{minipage}{0.5\textwidth}

    {\bfseries Допущен к защите: }\hrulefill \\
    {\bfseries Заведующий кафедрой: }\\
        Должность, что-то еще.\\
        Дата.\\
    {\bfseries Выполнил: }Студент группы 85-07\\
        Калашников М. А.\\
        Подпись.\\
    {\bfseries Научный руководитель: }\\
        Кандидат физико-математических наук, Чирков А. Ю.\\
        Подпись.\\

\end{minipage}
\end{flushright} 

This is what I need:

First requirement

I just want to add some spaces in certain strokes.
I have tried to use \hfill, \indent and some other approaches but it seems they don't work inside minipage. There should be some easy way to do it (I've spent more 3 hours without results).

Update: step2.
Second requirement
Please take a look also at this one. How do I align some text blocks to the right?
I believe there also should be introduced a \newcommand, but I'm still in the process of figuring out…

Best Answer

Since your data follow a well defined scheme, here's a possibility:

\documentclass{article}
\usepackage[T2A]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[russian]{babel}

\newcommand{\specialpar}[1]{%
  \par\hangindent=3em \hangafter=1
  \textbf{#1: }\ignorespaces}

\begin{document}
\begin{flushright}
\begin{minipage}{0.6\textwidth}
  \specialpar{Допущен к защите}\hrulefill

  \specialpar{Заведующий кафедрой}\\
    Должность, что-то еще.\\
    Дата.

  \specialpar{Выполнил} Студент группы 85-07\\
    Калашников М. А.\\
    Подпись.

  \specialpar{Научный руководитель}\\
    Кандидат физико-математических наук, Чирков А. Ю.\\
    Подпись.
\end{minipage}
\end{flushright}
\end{document}

Don't add \\ at the end of a "special paragraph"; the blank line between two of them is optional.

enter image description here

Each "special paragraph" is typeset with hanging indentation of 3em (\hangindent=3em) starting after the first line (\hangafter=1).

The argument to \specialpar is the part that should go in bold face.


What does go wrong in a minipage? To begin with, the \parindent parameter is set to zero, so using \indent is useless.

Here we use a low level feature that's not really supported by LaTeX, but in some cases can come handy, because it's more easily realized than going with a customized list environment.

Our \specialpar command just absorbs as argument what should go in boldface and followed by the colon; then it starts a new paragraph, just to be safe, and sets the two "paragraph shape" parameters. With \hangindent one specifies the amount of left indentation, with \hangafter how many lines should be typeset before the indentation takes place. Finally, the boldface text (with added colon and space) is typeset and \ignorespaces is issued, so spaces after the closing brace of the argument will be ignored.

Are there other methods? Yes. For instance one could do with setting \leftskip:

\newenvironment{dopuschchen}[1][.6\textwidth]
  {\begin{flushright}\begin{minipage}{#1}\leftskip=3em }
  {\end{minipage}\end{flushright}}
\newcommand{\specialpar}[1]{\par\hspace*{-3em}\textbf{#1: }\ignorespaces}

and then

\begin{dopuschchen}
  \specialpar{Допущен к защите}\hrulefill

  \specialpar{Заведующий кафедрой}\\
    Должность, что-то еще.\\
    Дата.

  \specialpar{Выполнил} Студент группы 85-07\\
    Калашников М. А.\\
    Подпись.

  \specialpar{Научный руководитель}\\
    Кандидат физико-математических наук, Чирков А. Ю.\\
    Подпись.
\end{dopuschchen}

would give the same result. The width reserved for the minipage can be given as optional argument to the new environment (default .6\textwidth):

\begin{dopuschchen}[.5\textwidth]

would make a narrower minipage

What's the difference with the above, apart making a new environment which might be advisable also for the original solution? The difference is that a setting to \leftskip goes on forever (respecting groups, so it will end with the minipage), while \hangindent and \hangafter are reset at each end of paragraph.

Another different solution is with the enumitem package.

\usepackage{enumitem}
\newenvironment{xdopuschchen}[1][.6\textwidth]
  {\begin{flushright}\begin{minipage}{#1}
   \begin{description}[
     nosep,leftmargin=3em,itemindent=-3em,labelsep=0pt,
     before=\let\makelabel\dopusmakelabel,
   ]}
  {\end{description}\end{minipage}\end{flushright}}
\newcommand{\dopusmakelabel}[1]{\textbf{#1: }}

The syntax for the environment would be

\begin{xdopuschchen}
  \item[Допущен к защите]\hrulefill

  \item[Заведующий кафедрой]\mbox{}\\
    Должность, что-то еще.\\
    Дата.

  \item[Выполнил] Студент группы 85-07\\
    Калашников М. А.\\
    Подпись.

  \item[Научный руководитель]\mbox{}\\
    Кандидат физико-математических наук, Чирков А. Ю.\\
    Подпись.
\end{xdopuschchen}

Notice the need of \mbox{} when \item[...] has to be directly followed by a line break.

See the documentation of enumitem for details about the last suggestion.

Related Question