Include/exclude defined frames in Beamer - include

I have a large Beamer file with many frames. Based on the presentation purpose, I want to include/exclude certain slides from the presentation. Is there a way to define the frames at the end of the document and call them up when wanted? Something like the following:
\documentclass{beamer}
\begin{document}
% including the frames
\include{F1}
\include{F2}
% \include{F3}
\include{F4}
% frame definitions
\begin{frame}[F1]
1
\end{frame}
\begin{frame}[F2]
2
\end{frame}
\begin{frame}[F3]
3
\end{frame}
\begin{frame}[F4]
4
\end{frame}
\end{document}
I know that I can go frame by frame and add <beamer:0> to exclude that frame, but since the presentation is too long it would be great if I had the possibility to do as above.

This is exactly what the \includeonlyframes command is made for:
\documentclass{beamer}
\includeonlyframes{%
F1,%
F2,%
%F3,%
F4,%
}
\begin{document}
\begin{frame}[label=F1]
1
\end{frame}
\begin{frame}[label=F2]
2
\end{frame}
\begin{frame}[label=F3]
3
\end{frame}
\begin{frame}[label=F4]
4
\end{frame}
\end{document}

I don't really consider the following very pretty, but you could define a \newcommand unique for each frame, where the command simply translates to a single value, 0 (excluded) or 1 (included). E.g.
\newcommand{\includeFrameA}{0} % exclude frame
\newcommand{\includeFrameB}{1} % include frame
Then, using a help command
\newcommand{\includeFrame}[1]{beamer:#1}
you can define your frames with the addition of <\includeFrame{\includeFrameX}> to the frame environment signature; in so including/excluding the frame depending on the value of \includeFrameX as specified in the header of your document.
The following example excludes frames "A" and "C", and the produced presentation includes only two pages, containing "B" and "D", respectively.
\documentclass{beamer}
\newcommand{\includeFrame}[1]{beamer:#1}
% one command per frame, 0/1 : exclude/include
\newcommand{\includeFrameA}{0}
\newcommand{\includeFrameB}{1}
\newcommand{\includeFrameC}{0}
\newcommand{\includeFrameD}{1}
\begin{document}
% frame definitions
\begin{frame}<\includeFrame{\includeFrameA}>
A
\end{frame}
\begin{frame}<\includeFrame{\includeFrameB}>
B
\end{frame}
\begin{frame}<\includeFrame{\includeFrameC}>
C
\end{frame}
\begin{frame}<\includeFrame{\includeFrameD}>
D
\end{frame}
\end{document}

Related

Subfigures in latex never shrinks to be on one row (pfd file)

I'm trying to adjust two subfigures into one row. This is my code:
\begin{figure}[ht]
\centering
\caption{Migration rates and nightlights in Albania in 1992-1995}
\begin{subfigure}[a]{0.3\textwidth}
\caption{Emigration rate before 1995 at the municipality level}
\label{fig: migration_rate}
\includegraphics[width=\linewidth, trim = 5cm 0cm 5cm 0cm, clip]{Figures/migration_rate.pdf}
\end{subfigure}
\begin{subfigure}[b]{0.3\textwidth}
\caption{Night luminosity in 1992}
\label{fig: nighlights}
\includegraphics[width=\linewidth, trim = 5cm 0cm 5cm 0cm, clip]{Figures/nightlight.pdf}
\end{subfigure}
\caption*{\footnotesize{\textbf{Notes}:}}.
\end{figure}
enter image description here
Even if I shrink the subfigure to tiny size (for example {0.01\textwidth}), the two always appear in one column. I have deep blank space on the left and right of both figures that I have tried to trim. Including or excluding "trim" does not change much.
How do I get the two into one row?
Thank you!

Generate equations with label in sharelatex

I have made the following equation in sharelatex:
\[ \frac{\delta u}{\delta x} + \frac{\delta v}{\delta y} = 0 \]
How can I automatically label this equation with a number?
I have the following before the beginning of my document. My code is a bit messy, but I hope it can show what the problem is that prevents equation from working.
How can I automatically label this equation with a number?
I have the following before the beginning of my document. My code is a bit messy, but I hope it can show what the problem is that prevents equation from working.
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{nomencl}
\makenomenclature
\usepackage[english]{babel}
\usepackage[round]{natbib}
\usepackage{natbib}
\setcitestyle{square}
\usepackage[utf8]
\usepackage[table, svgnames, dvipsnames]{xcolor} %color row
\usepackage{makecell}
\renewcommand\theadfont{\normalsize}
\usepackage{caption}
\usepackage{siunitx}
\usepackage[justification=centering,font=small,labelfont=bf,tableposition=top]{caption}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[bottom]{footmisc}
\usepackage[margin=1.1in]{geometry}
\geometry{a4paper,total={170mm,257mm},left=22mm,right=22mm,top=30mm,bottom=20mm}
\usepackage{booktabs}
\usepackage[numbers]{natbib}
\usepackage{float}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{array}
\usepackage{blindtext}
\usepackage{color}
\usepackage{comment}
\usepackage{fancyhdr}
\usepackage{float}
\usepackage{footnote}
\usepackage{gensymb}
\usepackage{graphicx}
\usepackage{graphics}
\usepackage{hyperref}
\usepackage{lastpage}
\usepackage{listings}
\usepackage{longtable}
\usepackage{nomencl}
\usepackage{pifont}
\usepackage{subcaption}
\usepackage{subfiles}
\usepackage{tablefootnote}
\usepackage{times}
\usepackage{tikz}
\usepackage{watermark}
\usepackage{pdfpages}
\usepackage[pdftex]{graphicx}
\usepackage{graphicx,subcaption}
%for the tables
\usepackage[margin=1in,letterpaper]{geometry} % text block parameters
\usepackage{tabularx,siunitx,booktabs}
\usepackage[skip=0.5\baselineskip]{caption}
\usepackage{newtxtext,newtxmath}
\newcommand\mX[1]{\multicolumn{1}{X}{#1}} % handy shortcut macros
\newcommand\mcc[1]{\multicolumn{2}{c}{#1}}
\newcommand\mcl[1]{\multicolumn{2}{l}{#1}}\usepackage[margin=1in,letterpaper]{geometry} % text
\usepackage{multirow}
\graphicspath{{./Figures/}}
\setlength\parindent{0pt}
\usetikzlibrary{arrows,calc,positioning,shadows,shapes}
\newcommand{\cmark}{\textcolor{green!80!black}{\ding{51}}}
\newcommand{\xmark}{\textcolor{red}{\ding{55}}}
\usepackage{enumitem}%make indented dots
\usepackage{textcomp}
\usepackage{amsmath}
% Array commands, depends on \usepackage{array}
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
% Something with captions, depends on \usepackage{caption}
\DeclareCaptionLabelFormat{andtable}{#1~#2 \& \tablename~\thetable}
% Front page settings depends on \usepackage{fancyhdr}
\pagestyle{fancy}
\lhead{Name}
\newcommand{\specialcell}[2][c]{%
\begin{tabular}[#1]{#{}c#{}}#2\end{tabular}}
\rhead{Project}
\renewcommand{\baselinestretch}{1.3} % Line spacing
% Color settings depends on \usepackage{color}
\definecolor{mygreen}{RGB}{28,172,0} % color values Red, Green, Blue
\definecolor{mylilas}{RGB}{170,55,241}
\begin{document}
I have tried several codes but nothing is working. Not even the equation option.
Thanks for help in advance!
There are several serve errors in your preamble. You must fix them, if you ignore them tex only syntax checks the rest of the document and you end up with something that might or might not be a valid pdf
you must not load the same package multiple times with different options. The log file will clearly tell you about the error because of an option clash. In your example this concerns geometry, graphicx and natbib
the line \usepackage[utf8] is an syntax error. You must give a package name, not just an option
many other packages are loaded multiple times and some of the options are outdated, you should take a bit of time and clean up this preamble
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{nomencl}
\makenomenclature
\usepackage[english]{babel}
\usepackage[round]{natbib}
%\usepackage{natbib}
\setcitestyle{square}
%\usepackage[utf8]
\usepackage[table, svgnames, dvipsnames]{xcolor} %color row
\usepackage{makecell}
\renewcommand\theadfont{\normalsize}
\usepackage{caption}
\usepackage{siunitx}
\usepackage[justification=centering,font=small,labelfont=bf,tableposition=top]{caption}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[bottom]{footmisc}
\usepackage[margin=1.1in]{geometry}
\geometry{a4paper,total={170mm,257mm},left=22mm,right=22mm,top=30mm,bottom=20mm}
\usepackage{booktabs}
%\usepackage[numbers]{natbib}
\usepackage{float}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{array}
\usepackage{blindtext}
\usepackage{color}
\usepackage{comment}
\usepackage{fancyhdr}
\usepackage{float}
\usepackage{footnote}
\usepackage{gensymb}
\usepackage{graphicx}
\usepackage{graphics}
\usepackage{hyperref}
\usepackage{lastpage}
\usepackage{listings}
\usepackage{longtable}
\usepackage{nomencl}
\usepackage{pifont}
\usepackage{subcaption}
\usepackage{subfiles}
\usepackage{tablefootnote}
\usepackage{times}
\usepackage{tikz}
\usepackage{watermark}
\usepackage{pdfpages}
%\usepackage[pdftex]{graphicx}
%\usepackage{graphicx,subcaption}
%for the tables
%\usepackage[margin=1in,letterpaper]{geometry} % text block parameters
\usepackage{tabularx,siunitx,booktabs}
\usepackage[skip=0.5\baselineskip]{caption}
\usepackage{newtxtext,newtxmath}
\newcommand\mX[1]{\multicolumn{1}{X}{#1}} % handy shortcut macros
\newcommand\mcc[1]{\multicolumn{2}{c}{#1}}
\newcommand\mcl[1]{\multicolumn{2}{l}{#1}}
%\usepackage[margin=1in,letterpaper]{geometry} % text
\usepackage{multirow}
\graphicspath{{./Figures/}}
\setlength\parindent{0pt}
\usetikzlibrary{arrows,calc,positioning,shadows,shapes}
\newcommand{\cmark}{\textcolor{green!80!black}{\ding{51}}}
\newcommand{\xmark}{\textcolor{red}{\ding{55}}}
\usepackage{enumitem}%make indented dots
\usepackage{textcomp}
\usepackage{amsmath}
% Array commands, depends on \usepackage{array}
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
% Something with captions, depends on \usepackage{caption}
\DeclareCaptionLabelFormat{andtable}{#1~#2 \& \tablename~\thetable}
% Front page settings depends on \usepackage{fancyhdr}
\pagestyle{fancy}
\lhead{Name}
\newcommand{\specialcell}[2][c]{%
\begin{tabular}[#1]{#{}c#{}}#2\end{tabular}}
\rhead{Project}
\renewcommand{\baselinestretch}{1.3} % Line spacing
% Color settings depends on \usepackage{color}
\definecolor{mygreen}{RGB}{28,172,0} % color values Red, Green, Blue
\definecolor{mylilas}{RGB}{170,55,241}
\begin{document}
\begin{equation}
\frac{\delta u}{\delta x} + \frac{\delta v}{\delta y} = 0
\end{equation}
\end{document}

Images not showing up in PDF compile of thesis in Latex (via Overleaf)

I have images inside a figures folder for my thesis. When I use the \includegraphics[]{} command in my chapterX.tex file, the image just won't appear (in normal mode, fast mode, or in the downloaded PDF). They seem to scale, but just won't appear.
I've tried using the graphicsx and graphics packages, but neither work.
\documentclass[
10pt,
english,
singlespacing,
draft,
parindent 20mm
headsepline,
chapterinoneline,
]{MastersDoctoralThesis}
\usepackage[utf8]{inputenc}
\usepackage{ctable}
\usepackage[T1]{fontenc}
\usepackage{minitoc}
\setcounter{minitocdepth}{2}
\setlength{\mtcindent}{24pt}
\usepackage{hyperref}
\hypersetup{
colorlinks=true,
linkcolor=blue,
filecolor=magenta,
urlcolor=cyan,
}
\usepackage{enumitem}
\setlist[itemize]{noitemsep}
\setlist[enumerate]{noitemsep}
\usepackage{graphicx} % Required for including images
\graphicspath{{figures/}} % Location of the graphics files
\geometry{
paper=a4paper, % Change to letterpaper for US letter
inner=3cm, % Inner margin
outer=3cm, % Outer margin
%bindingoffset=.5cm, % Binding offset
top=1.5cm, % Top margin
bottom=1.5cm, % Bottom margin
%showframe, % Uncomment to show how the type block is set on the page
}
\begin{document}
\chapter{Conceptual framework}
\label{Chapter3}
\minitoc
\section{Introduction}
Below is Jackendoff's parallel architecture.
\includegraphics{figures/jackendoffpa.jpeg}
You need to remove the draft option to see your images:
\documentclass[
10pt,
english,
singlespacing,
%draft,
parindent 20mm
headsepline,
chapterinoneline,
]{MastersDoctoralThesis}
\usepackage[utf8]{inputenc}
\usepackage{ctable}
\usepackage[T1]{fontenc}
\usepackage{minitoc}
\setcounter{minitocdepth}{2}
\setlength{\mtcindent}{24pt}
\usepackage{hyperref}
\hypersetup{
colorlinks=true,
linkcolor=blue,
filecolor=magenta,
urlcolor=cyan,
}
\usepackage{enumitem}
\setlist[itemize]{noitemsep}
\setlist[enumerate]{noitemsep}
\usepackage{graphicx} % Required for including images
\graphicspath{{figures/}} % Location of the graphics files
\geometry{
paper=a4paper, % Change to letterpaper for US letter
inner=3cm, % Inner margin
outer=3cm, % Outer margin
%bindingoffset=.5cm, % Binding offset
top=1.5cm, % Top margin
bottom=1.5cm, % Bottom margin
%showframe, % Uncomment to show how the type block is set on the page
}
\begin{document}
\chapter{Conceptual framework}
\label{Chapter3}
\minitoc
\section{Introduction}
Below is Jackendoff's parallel architecture.
\includegraphics{jackendoffpa}
\end{document}

Image numbering depending on the partition number in which the image is displayed

How can I make captions under images in Fig. 1.1:, Fig. 1.2:, Fig. 2.1:, Fig. 2.2: depending on the section number and not just sequentially from 1 for all images in the article
For example code:
\begin{figure}[htbp]
\minipage{0.32\textwidth}
\centering\includegraphics[width=\linewidth]{images/1.png}
\caption{caption 1}\label{Fig_1}
\endminipage\hfill
\minipage{0.32\textwidth}%
\centering\includegraphics[width=\linewidth]{images/2.png}
\caption{caption 2}\label{Fig_2}
\endminipage\hfill
\minipage{0.32\textwidth}%
\centering\includegraphics[width=\linewidth]{images/3.png}
\caption{caption 3}\label{Fig_3}
\endminipage
\end{figure}
Without any additional packages, latex itself provides the macro \counterwithin which allows to number the figures on a per section basis:
\documentclass{article}
\usepackage{graphicx}
\counterwithin{figure}{section}
\begin{document}
\section{title}
\begin{figure}[htbp]
\begin{minipage}{0.32\textwidth}
% \centering
\includegraphics[width=\linewidth]{example-image-duck}
\caption{caption 1}
\label{Fig_1}
\end{minipage}
\hfill
\begin{minipage}{0.32\textwidth}%
% \centering
\includegraphics[width=\linewidth]{example-image-duck}
\caption{caption 2}
\label{Fig_2}
\end{minipage}
\hfill
\begin{minipage}{0.32\textwidth}%
% \centering
\includegraphics[width=\linewidth]{example-image-duck}
\caption{caption 3}
\label{Fig_3}
\end{minipage}
\end{figure}
\end{document}
(\centering is not necessary if the images already have the same width as the minipage)
There is an answer to this question in tex.stackechange https://tex.stackexchange.com/questions/28333/continuous-v-per-chapter-section-numbering-of-figures-tables-and-other-docume
It redefines counters with the chngcntr package.
But in my opinion, the simpler is to use the floatpackage. It allows to redefine floating environments, with a specific graphic appearance, position, etc, and numbering scheme.
\documentclass{article}
\usepackage{graphicx}
\usepackage{float}
% We define a new float environment called image.
% htbp means 'images' will be positioned preferably here, then at top, bottom or
% on a new page
% info on labels will go to file xx.lim (list of images)
% and it will numbered within sections
\newfloat{image}{htbp}{lim}[section]
% and we want 'Fig.' to appear on the caption
\floatname{image}{Fig.}
\begin{document}
\section{A first section}
blah blah. Look at image \ref{im1}. blah blah
\begin{image}
\centering
\includegraphics[width=3cm]{example-image}
\caption{An image}\label{im1}
\end{image}
\section{A second section}
blah blah. And now consider images \ref{im2} and \ref{im3}. blah blah
\begin{image}
\centering
\hfill\includegraphics[width=3cm]{example-image}\hfill\includegraphics[width=3cm]{example-image}\hfill\includegraphics[width=3cm]{example-image}\hfill
\caption{Now a bunch with several images}\label{im2}
\end{image}
blah blah
\begin{image}
\centering
\begin{tabular}{cc}
\includegraphics[width=3cm]{example-image} &\includegraphics[width=3cm]{example-image}\\
Image A&Image B
\end{tabular}
\caption{And two last images}\label{im3}
\end{image}
\end{document}
If you have several images in a fig, just place them as any text. In TeX, images are considered as (large) characters and the standard positioning methods apply. In the first example, I used \hfill to spread them evenly on a line, and in the second a tabular to include small comments on the images. But many other methods, like minipages, can be used. But if your image set is too long to fit on a line, unwanted line breaks may appear.
Unrelated, but any people use the float package because it also defines a new placement directive 'H' that means more or less 'place the float Here and nowhere else'. And modifying the graphics appearance of floats is also very useful.
Here is another solution without the float package
\documentclass{article}
\usepackage{graphicx}
\usepackage{chngcntr}
% change counter numbering
\counterwithin{figure}{section}
\begin{document}
\section{A first section}
blah blah. Look at images \ref{im1}, \ref{im2} and \ref{im3}. blah blah
\begin{figure}[h]
\begin{minipage}{0.3\linewidth}
\centering
\includegraphics[width=\linewidth]{example-image}
\caption{image 1}\label{im1}
\end{minipage}
\hfill
\begin{minipage}{0.3\linewidth}
\centering
\includegraphics[width=\linewidth]{example-image}
\caption{image 2}\label{im2}
\end{minipage}
\hfill
\begin{minipage}{0.3\linewidth}
\centering
\includegraphics[width=\linewidth]{example-image}
\caption{image 3}\label{im3}
\end{minipage}
\centering
\end{figure}
\end{document}

Converting grayscale JPEG image to RGB leads to 9 channels

Trying to convert some grayscale images to RGB (1,1,1).. I have a folder of about 1500 images that I need batch converted using the code below (which works well with individual images)
Interestingly enough,
imwrite(repmat(imread(files(1).name), [1 1 3]),files(1).name)
imwrite(repmat(imread(files(2).name), [1 1 3]),files(2).name)
imwrite(repmat(imread(files(3).name), [1 1 3]),files(3).name)
...(and so forth)
works just fine
files = dir('*.jpeg')
for I=1:length(files)
imwrite(repmat(imread(files(i).name), [1 1 3]),files(i).name)
display(i)
end
Error using writejpg (line 46)
Data with 9 components not supported for JPEG files.
Error in imwrite (line 485)
feval(fmt_s.write, data, map, filename, paramPairs{:});
You need to do two things:
Use the correct variable name for looping, i.e. i or I but not a mix! Note that i has a built in definition as the imaginary constant, so you're better of using I, or something different entirely.
You show a warning for JPEGs with 9 elements not being supported when trying to write the file. This suggests you've blindly used repmat to triplicate an image which is already RBG.
We can address both of these like so:
files = dir('*.jpeg')
for k = 1:length(files)
img = imread( files(k).name ); % Load the image first
% Convert greyscale to RBG if not already RGB
% If it's already RBG, we don't even need to overwrite the image
if size(img,3) == 1
imwrite(repmat(img, [1 1 3]), files(k).name);
end
% Display progress
display(k)
end

Resources