I restyled the \section and \subsection a little bit, to better suite my needs when writing assignments. Using titlesec, I moved the (sub)section number to the right of the (sub)section title. In my preamble:

\usepackage[compact,explicit]{titlesec}

\def\thesection{\Roman{section}}
\titleformat{\section}[hang]{\Large\bfseries}{}{0pt}{#1 \thesection}
\def\thesubsection{\roman{subsection}:}
\titleformat{\subsection}[runin]{\large\itshape}{}{0pt}{#1 \thesubsection:}

In my documents, I usually use \section{Part} and \subsection{Question}, depending on the assignment. The advantage of course is, that I don't have to worry about Question numbering.

However, the problem is that in the table of contents the (sub)section number is of course still displayed on the left, while I want both on the right as well.

I looked at the tocloft package, but I can't figure out this particular case.

• A tip: You can use backticks ` to mark your inline code as I did in my edit. – egreg Nov 20 '12 at 23:28
• I will keep it in mind for next time, thanks. – altabq Nov 21 '12 at 11:56

Here's a possible solution; the idea is to set tocdepth to 0 inside the redefinition for the section headings so they won't be automatically included in the ToC; then the titles are manually included using \addcontentsline with the desired formatting (title, number, page number); finally, the etoolbox package is used to restore the tocdepth counter to its default value:

\documentclass{article}
\usepackage[compact,explicit]{titlesec}
\usepackage{etoolbox}

\def\thesection{\Roman{section}}
\def\thesubsection{\roman{subsection}}

\titleformat{\section}[hang]
{\Large\bfseries}{}{0pt}{#1 \thesection%
\titleformat{name=\section,numberless}[hang]
{\Large\bfseries}{}{0pt}{#1}
\titleformat{\subsection}[runin]
{\large\itshape}{}{0pt}{#1 \thesubsection:}
\titleformat{name=\subsection,numberless}[runin]
{\large\itshape}{}{0pt}{#1:}

\begin{document}

\tableofcontents
\section{Test Section One}
\subsection{Test}
\section{Test Section Two}

\end{document}

Not relevant to the problem mentioned, but I provided also definitions to be applied to the unnumbered sections and subsections (produced with \section* and \subsection*) to prevent numbering them.

Another option, is to use a new auxiliary file (with extension .moc, for example) and redefine \tableofcontents so that \@starttoc uses moc instead of toc; this simple trick simplifies the solution (no patching required) and it is more suitable in case the new formatting has to be applied to more sectional units (as was requested in a comment to the original answer); here's a complete example illustrating this approach:

\documentclass{article}
\usepackage[compact,explicit]{titlesec}

\def\thesection{\Roman{section}}
\def\thesubsection{\roman{subsection}}

\titleformat{\section}[hang]
{\Large\bfseries}{}{0pt}{#1 \thesection%
}
\titleformat{name=\section,numberless}[hang]
{\Large\bfseries}{}{0pt}{#1}
\titleformat{\subsection}[runin]
{\large\itshape}{}{0pt}{#1 \thesubsection:%
\titleformat{name=\subsection,numberless}[runin]
{\large\itshape}{}{0pt}{#1:}

\makeatletter
\renewcommand\tableofcontents{%
\section*{\contentsname
\@mkboth{%
\MakeUppercase\contentsname}{\MakeUppercase\contentsname}}%
\@starttoc{moc}%
}
\makeatother
\begin{document}

\tableofcontents
\section{Test Section One}