Is there such a thing as an environment for defining problems? See this picture for an example of what I want to achieve: example problem definition


  • Welcome to TeX.SX! amsthm or ntheorem packages perhaps? Your question is not very precise
    – user31729
    Jul 16, 2015 at 17:02
  • 1
    Yeah sorry I'm new to latex. And thank you :) I'm just looking for a way to properly format a problem definition like shown in the pic, where I have a problem title, an input and a question, such that the input and the question are aligned as seen above. I tried the algorithm2e package, but it messes up the alignment.
    – Peter W
    Jul 16, 2015 at 17:16

2 Answers 2


You can create an unbreakable structure that would set the question:

enter image description here


\newcommand{\problemtitle}[1]{\gdef\@problemtitle{#1}}% Store problem title
\newcommand{\probleminput}[1]{\gdef\@probleminput{#1}}% Store problem input
\newcommand{\problemquestion}[1]{\gdef\@problemquestion{#1}}% Store problem question
  \problemtitle{}\probleminput{}\problemquestion{}% Default input is empty
  \BODY% Parse input
  \begin{tabularx}{\textwidth}{@{\hspace{\parindent}} l X c}
    \multicolumn{2}{@{\hspace{\parindent}}l}{\@problemtitle} \\% Title
    \textbf{Input:} & \@probleminput \\% Input
    \textbf{Question:} & \@problemquestion% Question



  \probleminput{A graph $G = (V,E)$ and a function $f : V \mapsto \mathbb{N}_0$.}
  \problemquestion{Is there an \emph{$f$-factor}, that is, a subgraph $G' = (V,E')$ of~$G$ such that
    $\text{deg}_{G'}(v) = f(v)$ for all $v \in V$?}



The problem environment requests you to use \problemtitle, \probleminput and \problemquestion (in any order) to set the title, input and question statement inside a tabularx.

  • That works just like a charm, thank you very much!
    – Peter W
    Jul 16, 2015 at 17:30
  • Aren’t you missing a closing \makeatother? But yes, works fine :)
    – Max Merz
    Dec 8, 2019 at 13:50

I wanted precisely what you asked, but framed, and with the opportunity of adding several rows to the table, for example Input, Output, or Instance and Task.

I wrote a solution starting from Werner's code using only tabularx which can produce different looking environments. The environment has an optional argument that can be one of

  • (empty or omitted) no framing around the environment
  • framed a single frame around the environment
  • lined two single horizontal lines above and below the environment
  • doublelined two double horizontal lines above and below the environment

You can type any number of lines with any boldface item on the left:

\begin{problem}[framed]{Title of my problem}
  Task: & Define a new ``problem'' environment. \\
  Problem: & The only keywords you can use to search on Google
    are ``latex'' ``problem'' ``definition'' ``environment''. \\
  Solution: & Be patient.

Example of problem environment

Most of the code is deciding whether the optional argument is empty, framed, lined, or doublelined. Credit to Joseph's answer for being able to use a macro inside the column definition of tabularx. Originally I had written an implementation that relied only on tabularx, but that conflicted with some packages (among which biblatex).

\usepackage{tabularx, environ}


% https://tex.stackexchange.com/a/199244/26355

        \textsc{\Large #2}%
        \textsc{\Large #2}%

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .