4

I want to have a slide that looks as follows:

  • At the top, I'd like to have a theorem statement in a tcbtheorem environment I've defined.
  • Below that, I'd like, after some vertical spacing, two columns of the following form.
  • The first row must have each element be a tcolorbox of the form I've defined; further, each of these should be able to hold a couple of lines of text in them, while not getting too wide (so they might have somewhat larger height than a box that has only line of text).
  • The subsequent rows should be tcolorboxes with a more plain look than those in the first row (I'd like to be able to customize these; so essentially, I'm asking for a different style in these rows).
  • I want the entire matrix to be revealed in the order: (row1, col1), (row1, col2), (row2, col1), (row2, col2), etc.

So far, I've managed to achieve very few of these goals. I'd really appreciate any help.

\documentclass{beamer}
\mode<presentation>
{
  \setbeamertemplate{navigation symbols}{}
  \setbeamertemplate{caption}[numbered]
}

\usepackage{tcolorbox}
\usepackage{tikz}
\usetikzlibrary{matrix,overlay-beamer-styles}

%%%%%%%%%
\usetikzlibrary{calc}
%%%%%%%%
\tcbuselibrary{theorems}


\newtcbtheorem[]{mylemmma}{Lemma}{colframe=green,colback=white, width=\textwidth}{lem}
\tcbset{colframe=green, colback=white}  
\resetcounteronoverlays{tcb@cnt@mylemmma}

\begin{document}
\section{Proofs}
\newtcbtheorem[]{mydef}{Problem Statement}{colframe=white, colback=white}{ps}
\tcbset{colframe=black, colback=white}              

\resetcounteronoverlays{tcb@cnt@mydef}

\begin{frame}[fragile]
    \begin{mylemmma}{theorem title}{thm}
     For any fixed iteration, 
    \[
    f(x+a)\approx f(x) + f'(x)(a) + 1/2 f''(z) (a^2)
    \]
    \end{mylemmma}

    \centering
\begin{tikzpicture}[optimization problem/.style = {%
            rounded corners, 
            draw = blue,
            thick,
            fill= white,
            inner ysep=5pt,
            inner xsep=5pt,
            align = center},
            ]

\matrix[matrix of nodes,row sep=1em,column sep=1em,
    nodes={anchor=west,
    visible on=<\pgfmatrixcurrentrow->,},
    column 1/.style={nodes={optimization problem,
    }}, 
    column 2/.style={nodes={optimization problem,
    alt=<-\the\numexpr\pgfmatrixcurrentcolumn-1>{opacity=0,text opacity=0}{},
    }}](M){
    vectors   &  matrices\\
    reason 1    & matrix reason 1\\
    reason 2    & matrix reason 2\\
};          

\end{tikzpicture}

\end{frame}


\end{document}


3

I am a big fan of one question per question, so this answer focuses on the last question because the answer is very simple.;-) The answer is

 visible on=<\the\numexpr-2+\pgfmatrixcurrentcolumn+2*\pgfmatrixcurrentrow\relax->

(where I added a -2 thanks for your comment!) or, in more detail,

\documentclass{beamer}
\mode<presentation>
{
  \setbeamertemplate{navigation symbols}{}
  \setbeamertemplate{caption}[numbered]
}

\usepackage{tcolorbox}
\usepackage{tikz}
\usetikzlibrary{matrix,overlay-beamer-styles}

%%%%%%%%%
\usetikzlibrary{calc}
%%%%%%%%
\tcbuselibrary{theorems}


\newtcbtheorem[]{mylemmma}{Lemma}{colframe=green,colback=white, width=\textwidth}{lem}
\tcbset{colframe=green, colback=white}  
\resetcounteronoverlays{tcb@cnt@mylemmma}

\begin{document}
\section{Proofs}
\newtcbtheorem[]{mydef}{Problem Statement}{colframe=white, colback=white}{ps}
\tcbset{colframe=black, colback=white}              

\resetcounteronoverlays{tcb@cnt@mydef}

\begin{frame}[fragile]
    \begin{mylemmma}{theorem title}{thm}
     For any fixed iteration, 
    \[
    f(x+a)\approx f(x) + f'(x)(a) + 1/2 f''(z) (a^2)
    \]
    \end{mylemmma}

    \centering
\begin{tikzpicture}[optimization problem/.style = {%
            rounded corners, 
            draw = blue,
            thick,
            fill= white,
            inner ysep=5pt,
            inner xsep=5pt,
            align = center},
            ]

\matrix[matrix of nodes,row sep=1em,column sep=1em,
    nodes={anchor=west,optimization problem,
    visible on=<\the\numexpr-2+\pgfmatrixcurrentcolumn+2*\pgfmatrixcurrentrow\relax->,},
    ](M){
    vectors   &  matrices\\
    reason 1    & matrix reason 1\\
    reason 2    & matrix reason 2\\
};          

\end{tikzpicture}

\end{frame}
\end{document}

enter image description here

How does that work? First of all, in tikzlibrarymatrix.code.tex you can find a couple of nice keys and objects which have not made their way to the pgfmanual yet. In this answer, the important ones are

  • \pgfmatrixcurrentcolumn, a TeX count, which indicates the column of the cell, and
  • \pgfmatrixcurrentrow, a TeX count indicating the row of the column.

Apart from that, you can find the keys

  • execute at end matrix,
  • execute at begin cell,
  • execute at end cell,
  • execute at empty cell,

which are hooks that can be used to fill matrices automatrixally. In the above,

visible on=<\the\numexpr-2+\pgfmatrixcurrentcolumn+2*\pgfmatrixcurrentrow\relax-> 

uses the visible on key from the overlay-beamer-styles library. The combination is chosen such that for overlay number 1 the cell 11 becomes visible since -2+column+2*row=1 for column=row=1, for overlay number 2 cell 12 becomes visible since -2+column+2*row=2 for column=2 and row=1, and so on. If you have a matrix with 7 columns, say, you will need thus

 visible on=<\the\numexpr-7+\pgfmatrixcurrentcolumn+7*\pgfmatrixcurrentrow\relax->

instead.

8
  • 1
    @lazulikid The relevant objects are not really documented in the manual. One can find them in the library. (I was supposed to write an article on this, but even though the article is more or less ready, it never got published.) However, \pgfmatrixcurrentcolumn and \pgfmatrixcurrentrow have a very simple interpretation: the column or row index of the matrix entry. There are many more useful keys. I understand and appreciate your desire to understand these things better. But this really can only be achieved with one question at a time... – user194703 May 25 '20 at 22:51
  • 1
    ... otherwise the usual thing happens: someone sees this, copies it without understanding it, addresses the other points, then theirs will be the accepted answer, and those who want to understand these things have to scroll down the list, below all the posts which chose a fancy color to get the tick. IMHO this is not optimal. So please consider asking one well-defined question such that others have a possibility to benefit from the question and answers. – user194703 May 25 '20 at 22:55
  • 1
    I have one last question about your line above. So I understand the meaning of pgfmatrixcurrentcolumn, but what are \the\numexpr and \relax? Why do we need those? The problem for me is, even though I learnt pgfmatrixcolumn (from a previous answer you gave me, in fact :)), my vocabulary isn't big enough, so I don't know of these new ways to combine pgfmatrixcolumn and rows. (Incidentally I figured out one of the other things in my question -- I can get the top row to be a different style by using row 1/.style = ... – lazulikid May 25 '20 at 23:05
  • 1
    @lazulikid I am in a meeting but will add more details later.... – user194703 May 25 '20 at 23:38
  • 1
    @lazulikid Good point! Fixed. – user194703 May 26 '20 at 1:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.