5

I would like to make similar document http://www.mojamatura.net/via-razina/dosadanji-ispiti-mat-a/201-matematika-a/1257-12-13-jesen-matematika-a

Document starts on later page. What have I done so far but still doesn't look that good. Enumerate puts items a way close to tcolorbox edge. Is there a way to connect tcolorboxes so that it would look similar?

\documentclass[12pt,article,a4paper]{memoir}
\usepackage[croatian]{babel}
\usepackage[pdftex]{graphicx}
\usepackage[cp1250]{inputenc}
\usepackage{tikz}
\usepackage[margin=.5in]{geometry}
\usepackage{amssymb,mathtools,amsmath,amsfonts,amsthm}
\usepackage{multicol}
\usepackage{wrapfig}
\usepackage{multicol}
\usepackage[T1]{fontenc}
\renewcommand*\familydefault{\sfdefault}
\usepackage{tcolorbox}
\usepackage{tabularx}
\usepackage{array}
\usepackage{colortbl}
\tcbuselibrary{skins}
\usepackage{pdflscape}
\usepackage{lipsum}
\pagestyle{empty}
\usepackage{booktabs}
\usepackage[locale=DE]{siunitx}

\newenvironment{zad}[1]{\indent \textsc{Zadatak} $\left[#1 \right]$}{\null\hfill$\qed$\hskip 2mm\vskip 2mm}
\usetikzlibrary{positioning}


\begin{document}
\tcbset{
enhanced,colback=white!10!white,colframe=black!50!black,colbacktitle=white!30!white,
coltitle=black,arc=0pt,outer arc=0pt,
}

\begin{enumerate}
\begin{tcolorbox}[title={\item\zad{4} This is first question},sidebyside,bottom=0mm,righthand ratio=0.15]

This is a \textbf{QUESTION}.
\tcblower
\begin{enumerate}
\item A
\item B
\end{enumerate}
\end{tcolorbox}
\begin{tcolorbox}[title={\item\zad{4} This is second question},sidebyside,bottom=0mm,righthand ratio=0.15]

\[\sum_{i=0}^{n}X_{k}=\sum_{i=0}^{n}\dfrac{A_{ij}^{k}}{k!}\]
\tcblower
\begin{enumerate}
\item C
\item D
\end{enumerate}.
\end{tcolorbox}


\end{enumerate}
\end{document}`
vejn
  • 271
  • 3
  • 11

1 Answers1

6

It is a bit unclear to me as to what you want to accomplish. The questions in your linked document look quite different from the ones that your code gives.

Also I don't really get what you try to accomplish with the \qed in your environment zad. So that's why I'll show you 2 solutions. Both solution define a new command \myquestion with 3 arguments: a question title, the question itself and a semicolon separated list of multiple choice answers.

First solution: In this solution I tried to get as close as possible to the layout suggested by your own code (zad command, \qed in the title, multiple choice answers on right hand side, ...)

\documentclass{article}
\usepackage[croatian]{babel}
\usepackage[T1]{fontenc}
\usepackage[cp1250]{inputenc}
\usepackage{xparse}
\usepackage{enumitem}
\usepackage{arydshln}
\usepackage{fullpage}
\usepackage{amsthm}
\renewcommand*\familydefault{\sfdefault}

\ExplSyntaxOn
\newcounter{questions}
\stepcounter{questions}
\renewcommand{\arraystretch}{2}

\newcommand{\zad}[1]{\textsc{Zadatak}\ $[#1]$}

\NewDocumentCommand{\myquestion}{m m m}{
    \par\noindent
    \begin{tabular}{|l:l|}
        \hline
        \multicolumn{2}{|l|}{\thequestions.\ #1 \hfill $\qed$} \\ \hline
        \parbox{.75\textwidth}{#2} & \parbox{.19\textwidth}{\choices:n{#3}} \\ \hline
    \end{tabular}
    \stepcounter{questions}
}

\cs_new:Npn \choices:n #1{
    \seq_set_split:Nnn \splitted_seq{;}{#1}
    \begin{enumerate}[label=\alph*)]
        \seq_map_inline:Nn \splitted_seq{
            \item ##1
        }
    \end{enumerate}
}
\ExplSyntaxOff

\begin{document}

\myquestion{\zad{4} This is the first question}
           {This is a \textbf{QUESTION}}
           {choice A; choice B; choice C}

\vspace{-1pt}

\myquestion{\zad{4} This is the second question}
           {\[ \sum_{i=0}^n X_k = \sum_{i=0}^n \frac{A_{ij}^k}{k!} \]}
           {choice A; choice B; choice C; choice D}

\end{document}

enter image description here

Second solution: This solution is a closer match to the document you linked to (multiple choice answers inside question box, pink box with tickboxes, ...)

\documentclass{article}
\usepackage[croatian]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{xparse}
\usepackage{enumitem}
\usepackage{fullpage}
\usepackage{amsthm}
\usepackage[table]{xcolor}
\usepackage{arydshln}
\usepackage{tikz}
\renewcommand*\familydefault{\sfdefault}

\ExplSyntaxOn
\newcounter{questions}
\stepcounter{questions}
\renewcommand{\arraystretch}{2}

\newcommand{\tickbox}{
\begin{tikzpicture}[scale=.3]
\fill[white] (0,0) -- (0,1) -- (1,1) -- (1,0) -- cycle;
\end{tikzpicture}
}

\NewDocumentCommand{\myquestion}{m m m}{
    \par\noindent
    \begin{tabular}{|l:l|}
        \hline
        \multicolumn{2}{|l|}{\thequestions.\ #1} \\ \hline
        \parbox{.85\textwidth}{\vspace{2mm} #2 \choices:n{#3}} & \cellcolor{red!15}\parbox{.09\textwidth}{\tickboxes:n{#3}} \\ \hline
    \end{tabular}
    \stepcounter{questions}
}

\cs_new:Npn \choices:n #1{
    \seq_set_split:Nnn \splitted_seq{;}{#1}
    \begin{enumerate}[label=\Alph*.]
        \seq_map_inline:Nn \splitted_seq{
            \item ##1
        }
    \end{enumerate}
}

\cs_new:Npn \tickboxes:n #1{
    \seq_set_split:Nnn \splitted_seq{;}{#1}
    \begin{enumerate}[label=\Alph*.]
        \seq_map_inline:Nn \splitted_seq{
            \item \tickbox
        }
    \end{enumerate}
}
\ExplSyntaxOff

\begin{document}

\myquestion{Intervals}
           {Koliko cijelih brojeva ima u intervalu $\left[-\frac{11}{4},3\right\rangle$?}
           {5; 6}

\vspace{-1pt}

\myquestion{Order of Operations}
           {Učenik je na džepnome računalu zbrojio brojeve $A$ i $B$. Dobiveni rezultat podijelio je s $C$. Taj je rezultat pomnožio s $D$. Koji izraz opisuje taj račun?}
           {$\frac{A+B}{CD}$; $\frac{(A+B)D}{C}$; $(A+B:C)\cdot D$; $A+B:\frac{c}{D}$}

\vspace{-1pt}

\myquestion{Unit Conversion}
           {Kolika je gustoća $1.8$ g/cm$^3$ izražena u kg/m$^3$?}
           {$0.018$ kg/m$^3$;$0.18$ kg/m$^3$;$1.8$ kg/m$^3$; $18$ kg/m$^3$; $180$ kg/m$^3$; $1800$ kg/m$^3$} 

\end{document}

enter image description here

Of course both solutions can be combined depending on what you actually want to accomplish.

  • Thanks! I wrote the code as close as my knoledge of latex provided. I didn't know how to remove spaces between tcolorboxes and make first question nicely visible. How to remove space between your \myquestion boxes so that looks as in document? – vejn Mar 25 '15 at 16:34
  • @vejn Change \vspace. I edited my answer from \vspace{.5cm} to \vspace{-1pt}. – Maarten Dhondt Mar 25 '15 at 16:45
  • That's the document. Thank you. Where did you learn latex ? I have some tutorials but I was wondering where was your source. – vejn Mar 25 '15 at 17:13
  • @vejn If in your opinion this is a correct answer, please consider accepting it. I learned LaTeX at University. – Maarten Dhondt Mar 25 '15 at 19:37
  • Can you suggest some pdf tutorial to create new environments and commands which includes everything you make? – vejn Mar 25 '15 at 19:50
  • http://tex.stackexchange.com/questions/11/what-are-good-learning-resources-for-a-latex-beginner This is not specific for new environments and commands but I'm sure it's explained in some of these tutorials. – Maarten Dhondt Mar 25 '15 at 19:54