Automatically instert multiple images in table from folder - latex

I need to input images into a table that i have created in latex, the problem is that i have hundreds of these and various tables to make, therefore i was looking for a way that allows me not to write every single name of image in the command. I have all the images in a overleaf folder and they all have similar names like: fake_image_MPI_rank_0_Epoch_92_Batch_400_N_image_16.png
my table looks like this:
\begin{table}[H]
\centering
\begin{tabular}{|c|c|c|c|c|c|}}
\hline
\includegraphics[width=20mm]{} &
\includegraphics[width=20mm]{} &
\includegraphics[width=20mm]{} &
\includegraphics[width=20mm]{} &
\includegraphics[width=20mm]{} &
\includegraphics[width=20mm]{} \\
\hline
\includegraphics[width=20mm]{} &
\includegraphics[width=20mm]{} &
\includegraphics[width=20mm]{} &
...
...
\end{tabular}
\end{table}
By looking online i realized that this could be done with a for loop or something similar. However didn't really find many examples or documentation that allows me to write that bunch of latex code. Does someone know how to do it?
logic behind files names
epoch: from 0 to above 1000 but i am interested in just a few of these (say from 998 to 1000)
batch: from 0 to 400 and is incremented of 100 ( so 0, 100, 200, ...)
image: from 1 to 10 with increments of 1
MPI_rank: Does NOT change (always 0)
Iterating over a few epochs (say from 998 to 1100) and inserting ALL images of ALL batches would produce enough content to create one of these tables.
link to overleaf example
https://www.overleaf.com/3116518543qnnrwdhsbdbg

All these picture probably won't fit on a single page, so I suggest to forgo the table and just place them side by side. This will be the easiest way to allow page breaks. You can add the caption with the \captionof macro from the caption package.
And without the table, the loops can easily be done with \foreach from the pgffor package. If you need lines, you could instead place the images into \fboxes, but using so many lines in a table is anyway bad style, so better remove them.
Some other comments:
don't load the same package multiple times
load hyperref last
\documentclass{article}
\usepackage[utf8]{inputenc}
%\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{amsmath,amsfonts,amssymb}
\usepackage{xcolor}
%\usepackage{url}
\usepackage[margin=1.0in]{geometry}
\usepackage{algorithm}
\usepackage[noend]{algpseudocode}
\usepackage{comment}
\usepackage{ifthen}
\usepackage{placeins}
\usepackage{authblk}
\usepackage{afterpage}
\usepackage{amsthm}
\usepackage{soul}
\usepackage[english]{babel}
%\usepackage{xcolor}
\graphicspath{ {./images/} }
\newtheorem*{remark}{\textbf{Remark}}
\usepackage{subcaption}
\usepackage{textgreek}
\usepackage[font={it}]{caption}
\usepackage{titlesec}
\usepackage{titling}
\usepackage{pgffor}
\usepackage{hyperref}
\date{November 2020}
\begin{document}
\section{Introduction}
In the IMAGES folder i loaded images from epoch 1218 batch 200 to epoch 1220 batch 0
\begingroup
\raggedright%
\foreach \epoche in {998,...,1000}{%
\foreach \batch in {0,100,...,400}{%
\foreach \x in {1,...,10}{%
\includegraphics[width=20mm]{IMAGES/fake_image_MPI_rank_0_Epoch_\epoche _Batch_\batch_N_image_\x }\hspace{0pt}%
}}}
\captionof{table}{Bla Bla bla}
\label{somekey}
\endgroup
\clearpage
\begingroup
\raggedright%
\foreach \epoche in {1219,...,1219}{%
\foreach \batch in {0,100,...,400}{%
\foreach \x in {1,...,10}{%
\fbox{\includegraphics[width=20mm]{IMAGES/fake_image_MPI_rank_0_Epoch_\epoche _Batch_\batch_N_image_\x }}\hspace{0pt}%
}}}
\captionof{table}{Bla Bla bla}
\label{somekeyy}
\endgroup
\end{document}

Related

How to I import and display my .csv file in a Beamer presentation?

I have a csv file called csv1.csv that looks like:
name|surname|grade
Maier|Hans,|A
Huber|Anna|B
Weißbäck|Werner|C
(So my csv is a table with 4 rows and 3 columns. There are tabular lines and not "|" in my csv file - like a spreadsheet.)
My actual file is a .csv file in my desktop that I imported in my overleaf. I have no idea why I am unable to simply display the table, let alone format it, using the csvsimple package. What I tried:
\documentclass[10pt]{beamer}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage{csvsimple}
\begin{document}
\begin{table}[h]
\centering
\csvautobooktabular{csv1.csv}
\end{table}
\caption{My File}
\end{document}
I just want to display my csv file in my beamer and format it a bit (capitalize headers, make them bold, etc) instead of pasting a screenshot of it. If there is any other package that can help me, please feel free to suggest! Thank you!
By default csvsimple assumes commas as the column separator; but your csv1.csv uses pipe characters. So you'll need to specify separator=pipe.
The \caption should also go before the \end{table}. So this should work:
\documentclass[10pt]{beamer}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage{csvsimple}
\begin{document}
\begin{frame}
\begin{table}
\csvautobooktabular[separator=pipe]{csv1.csv}
\caption{My File}
\end{table}
\end{frame}
\end{document}
(Demo on Overleaf: https://www.overleaf.com/read/tnbwbwfbjpqg)
Adapting the example of the following link, you can get the following result
This is the code:
\documentclass{beamer}
\usepackage{csvsimple}
% file content grade.csv
% name,givenname,matriculation,gender,grade
% Maier,Hans,12345,m,1.0
% Huber,Anna,23456,f,2.3
% Weisbaeck,Werner,34567,m,5.0
\begin{document}
\begin{frame}{Title frame}
\begin{table}
\caption{Caption of table}
\begin{tabular}{l|c}%
\hline
\bfseries Person & \bfseries Matr.~No.% specify table head
\csvreader[head to column names]{grade.csv}{}% use head of csv as column names
{\\\hline\givenname\ \name & \matriculation}% specify your columns here
\end{tabular}
\end{table}
\end{frame}
\end{document}
Keep in mind that the *.CSV file is in the same work board and the data is separated by a ","

it doesn't show the figure but just a frame and inside the file name, although the image file is uploaded in the same folder on overleaf

May the problem consist in wrong packages? The image was uploaded successfully in the folder I tried even with the function wrapfigure but the result is the same. And I tried to use the image not through the \newcommand but it cannot be read properly anyway.
\documentclass[12pt,a4paper,oneside,draft]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{imakeidx}
\makeindex[columns=3, title=Alphabetical Index, intoc]
\usepackage{graphics}
\usepackage{graphicx}
\usepackage{wrapfig}
\graphicspath{ {images/} }
\usepackage [a4paper,top=2cm,bottom=0cm,left=1cm,right=1cm]{geometry}
\textheight=5000px % Saving trees ;-)
\usepackage{url}
%%% Macros
%%% ------------------------------------------------------------
\newlength{\spacebox}
\settowidth{\spacebox}{8888888888} % Box to align text
\newcommand{\sepspace}{\vspace*{15em}} % Vertical space macro
\newcommand{\titolo}[4]{
**\begin{figure}[t]
\includegraphics[width=5cm]{logoPolimi.png}
\centering
\end{figure}**
%\vspace*{15em}
\sepspace
\centering\textbf{\huge{#1}}
\vspace{15em}
\centering\textbf{#2}
\vspace{2em}
\textbf{#3}
\vspace{2em}
\textbf{#4}}
\usepackage{caption}
%\pagenumbering{roman}
\begin{document}
\titolo{Digital Channel}{Mario Rossi}{Management Engineering}{Politecnico di Milano}
\end{document}
Thanks in advance
The figure does not appear, because you are using draft as document class option.
Unrelated to your problem, but
font commands like \huge are switches and don't take an argument. So instead of \huge{...}, you should use {\huge ...}
you don't need the graphics package if you also load graphicx
if your tex distribution is up to date, you can also skip \usepackage[utf8]{inputenc} because this is the default for some years
\documentclass[12pt,a4paper,oneside,
%draft
]{article}
%\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{imakeidx}
\makeindex[columns=3, title=Alphabetical Index, intoc]
%\usepackage{graphics}
\usepackage{graphicx}
\usepackage{wrapfig}
\graphicspath{ {images/} }
\usepackage [a4paper,top=2cm,bottom=0cm,left=1cm,right=1cm]{geometry}
\textheight=5000px % Saving trees ;-)
\usepackage{url}
%%% Macros
%%% ------------------------------------------------------------
\newlength{\spacebox}
\settowidth{\spacebox}{8888888888} % Box to align text
\newcommand{\sepspace}{\vspace*{15em}} % Vertical space macro
\newcommand{\titolo}[4]{
\begin{figure}[t]
\includegraphics[width=5cm]{example-image.png}
\centering
\end{figure}
%\vspace*{15em}
\sepspace
\centering\textbf{\huge #1}
\vspace{15em}
\centering\textbf{#2}
\vspace{2em}
\textbf{#3}
\vspace{2em}
\textbf{#4}}
\usepackage{caption}
%\pagenumbering{roman}
\begin{document}
\titolo{Digital Channel}{Mario Rossi}{Management Engineering}{Politecnico di Milano}
\end{document}

Several subfigures in a row. Latex only put 2 in a row. subfloat error

i´m trying to align several subfigures in a row. 2 figures are working fine. When trying to include the third subfigure following err message appears: File ended while scanning use of #subfloat. \include{doc}
This tex document is included in the main file with packages:
\usepackage{graphicx}
\usepackage{subfigure}
\usepackage{subcaption}
%%%%%%new doc
\begin{figure}[h!]
\centering
\subfigure[a]{\includegraphics[width=0.1\textwidth]{Logos/Symbol_One_flow_path}}
\subfigure[b]{\includegraphics[width=0.1\textwidth]{Logos/1920px-Symbol_Two_flow_paths}}
\subfigure[c]{\includegraphics[width=0.1\textwidth]{Logos/Symbol_Two_flow_paths_(diagonally)} \subfigure[d]{\includegraphics[width=0.3\textwidth{Logos/Symbol_Two_flow_paths_with_connection}
\subfigure[e]{\includegraphics[width=0.3\textwidth]{Logos/graph}
\end{figure}
this issue is probably due to the missing } at the end of figures c,d and e.
That can explain why you just have the figures a and b.
\usepackage{graphicx}
\usepackage{subfigure}
\usepackage{subcaption}
\begin{figure}[h!]
\centering
\subfigure[a]{\includegraphics[width=0.1\textwidth]{Logos/Symbol_One_flow_path}}
\subfigure[b]{\includegraphics[width=0.1\textwidth]{Logos/1920px-Symbol_Two_flow_paths}}
\subfigure[c]{\includegraphics[width=0.1\textwidth]{Logos/Symbol_Two_flow_paths_(diagonally)}} %one } was missing here !
\subfigure[d]{\includegraphics[width=0.3\textwidth{Logos/Symbol_Two_flow_paths_with_connection}} % here also
\subfigure[e]{\includegraphics[width=0.3\textwidth]{Logos/graph}} %and here
\end{figure}

Try to move the table to the left, but failed

I was trying to reposition my table a bit left to the page, so I try \hskip -2cm or \hspace{-2cm} But non of these can move the table and here is my code:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{float}
\usepackage{array}
\usepackage{booktabs,caption}
\usepackage[flushleft]{threeparttable}
\usepackage{indentfirst}
\setlength\extrarowheight{2pt}
\title{}
\author{}
\begin{document}
\maketitle
\section{Introduction}
\section{Data Summary}
\begin{table}[H]
\begin{threeparttable}
\small
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\hskip -2cm
\caption{Summary of numeric variables}
\begin{tabular}{l*{1}{ccccc}}
\hline\hline
&\multicolumn{5}{c}{(1)} \\
&\multicolumn{5}{c}{} \\
& count& mean& sd& min& max\\
\hline
Unemployment Rate & 170& 8.3323& 4.1395& 3.1000& 26.0919\\
log of spending per person for secondary education& 168& 9.0229& 0.4344& 7.6109& 9.9616\\
log of spending per person for teriary education& 165& 9.5241& 0.3967& 8.7797& 10.7478\\
log of exchange rate& 170& 1.0983& 2.0997& -0.4986& 7.0522\\
log of GDP per person& 168& 10.5306& 0.3592& 9.7330& 11.5213\\
log of GDP fixed purchasing power& 165& 27.0045& 1.4905& 23.3668& 30.5051\\
log of GDP growth & 159& 1.2268& 0.7896& -1.7458& 3.0063\\
Long-term interest rate on government bonds& 165& 3.8447& 2.1387& 0.5511& 10.5465\\
Short-term interest rate& 170& 1.7675& 1.9971& 0.0078& 10.3317\\
\hline\hline
\end{tabular}
\begin{tablenotes}
\small
\item Source: OECD (2019), Education at a Glance Database, http://stats.oecd.org
\end{tablenotes}
\end{threeparttable}
\end{table}
\section{Methodology}
\end{document}
and my table looks like this:
and I want to make my table left about a least 1.5cm.
Is there other way to do this?
Having your table project into the margin is not a good style for a layout that is not specifically designed to have additional space in the margins for this. The margin should belong to the reader to easily hold your document, adding notes etc. If there is not enough space things like Fermat's Last Theorem are your fault :)
Instead I suggest to use a tabularx to fit the table into the available space:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{float}
\usepackage{array}
\usepackage{booktabs,caption}
\usepackage[flushleft]{threeparttable}
\usepackage{indentfirst}
\setlength\extrarowheight{2pt}
\usepackage{tabularx}
\usepackage{siunitx}
\title{}
\author{}
\begin{document}
\maketitle
\section{Introduction}
\section{Data Summary}
\begin{table}[H]
\begin{threeparttable}
\small
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\hskip -2cm
\caption{Summary of numeric variables}
\begin{tabularx}{\linewidth}{#{}XS[table-format=3.0]S[table-format=2.4]S[table-format=1.4]S[table-format=-1.4]S[table-format=2.4]#{}}
\toprule
&\multicolumn{5}{c}{(1)} \\\addlinespace
& {count}& {mean}& {sd}& {min}& {max}\\
\midrule
Unemployment Rate & 170& 8.3323& 4.1395& 3.1000& 26.0919\\
log of spending per person for secondary education& 168& 9.0229& 0.4344& 7.6109& 9.9616\\
log of spending per person for teriary education& 165& 9.5241& 0.3967& 8.7797& 10.7478\\
log of exchange rate& 170& 1.0983& 2.0997& -0.4986& 7.0522\\
log of GDP per person& 168& 10.5306& 0.3592& 9.7330& 11.5213\\
log of GDP fixed purchasing power& 165& 27.0045& 1.4905& 23.3668& 30.5051\\
log of GDP growth & 159& 1.2268& 0.7896& -1.7458& 3.0063\\
Long-term interest rate on government bonds& 165& 3.8447& 2.1387& 0.5511& 10.5465\\
Short-term interest rate& 170& 1.7675& 1.9971& 0.0078& 10.3317\\
\bottomrule
\end{tabularx}
\begin{tablenotes}
\small
\item Source: OECD (2019), Education at a Glance Database, http://stats.oecd.org
\end{tablenotes}
\end{threeparttable}
\end{table}
\section{Methodology}
\end{document}
Some other comments:
Try to avoid [H], this is usually a guaranty for bad suboptimal placement of floats. I suggest [htbp] instead
*{1}{ccccc} can be shorted to either ccccc or *{5}{c}
You already load the booktabs package, so I suggest to use \toprule, \midrule and \bottomrule instead of \hline because they have much better spacing around them
instead of manually adding empty lines in the table, I suggest the \addlinespace macro from the booktabs package
With the S column from the siunitx package you can align the numbers by their decimal marker and use actual minus signs instead of cheating with hyphens
you should check the significant figures of your values. If your standard deviation is between 0.3 and 4.1, it makes no sense to give the values with 4 decimal places.

Undefined control sequence \chapter

Hello I'm new in Latex.
I was trying to write my thesis, using the MasterDoctoralClass.cls.
This is my main.tex:
\documentclass[
11pt,
english,
singlespacing,
headsepline
]{MastersDoctoralThesis}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{mathpazo}
\usepackage[backend=bibtex,style=authoryear,natbib=true]{biblatex} )
\addbibresource{example.bib}
\usepackage[autostyle=true]{csquotes}
%----------------------------------------------------------------------------------------
% MARGIN SETTINGS
%----------------------------------------------------------------------------------------
\geometry{
paper=a4paper,
inner=2.5cm,
outer=3.8cm,
bindingoffset=.5cm,
top=1.5cm,
bottom=1.5cm
}
%----------------------------------------------------------------------------------------
% THESIS INFORMATION
%----------------------------------------------------------------------------------------
\thesistitle{Title Thesis}
\supervisor{Prof. X \textsc{Y} \\ Dr. Z \textsc{W}}
\degree{Master of Science in Electronic Engineering}
\author{Name \textsc{Surname}}
\subject{Electronic Engineering}
\keywords{}
\university{{Università}}
\department{{Department of Information Engineering, Electronics and Telecommunications}}
\group{{Master of Science in Electronic Engineering}}
\faculty{{Faculty of Information Engineering, Informatics and Statistics}}
\AtBeginDocument{
\hypersetup{pdftitle=\ttitle}
\hypersetup{pdfauthor=\authorname}
\hypersetup{pdfkeywords=\keywordnames}
}
\begin{document}
\frontmatter
\pagestyle{plain}
%----------------------------------------------------------------------------------------
% TITLE PAGE
%----------------------------------------------------------------------------------------
\begin{titlepage}
\begin{center}
\includegraphics[scale=1]{logo.jpg}
\end{center}
\begin{center}
\vspace*{.01\textheight}
\textsc{\Large Master Thesis}\\[1cm]
\HRule \\[0.4cm]
{\huge \bfseries \ttitle\par}\vspace{0.4cm}
\HRule \\[1.5cm]
\begin{minipage}[t]{0.4\textwidth}
\begin{flushleft} \large
\emph{Author:}\\
\href{}{\authorname}
\end{flushleft}
\end{minipage}
\begin{minipage}[t]{0.4\textwidth}
\begin{flushright} \large
\emph{Supervisor:} \\
{\supname}
\end{flushright}
\end{minipage}\\[2cm]
\begin{center}
\includegraphics[scale=0.4]{logo2.jpg}\hfill\includegraphics[scale=0.5]{logo3.jpg}
\end{center}
\vspace*{1.5cm}
\groupname\\\deptname\\[1.5cm]
\vfill
\rule{3cm}{1pt}\\
{\large \today}\\[4cm]
%\includegraphics{Logo}
\vfill
\end{center}
\end{titlepage}
%----------------------------------------------------------------------------------------
% QUOTATION PAGE
%----------------------------------------------------------------------------------------
\vspace*{0.2\textheight}
\begin{flushright}
\thispagestyle{empty}
\vspace*{5cm}
\itshape\enquote{Something}\\[0.3cm]
\end{flushright}
\hfill Name
%----------------------------------------------------------------------------------------
% ABSTRACT PAGE
%----------------------------------------------------------------------------------------
\begin{abstract}
\addchaptertocentry{\abstractname}
The Thesis Abstract is written here (and usually kept to just this page). The page is kept centered vertically so can expand into the blank space above the title too\ldots
\end{abstract}
%----------------------------------------------------------------------------------------
% ACKNOWLEDGEMENTS
%----------------------------------------------------------------------------------------
\begin{acknowledgements}
\addchaptertocentry{\acknowledgementname}
The acknowledgments and the people to thank go here, don't forget to include your project advisor\ldots
\end{acknowledgements}
%----------------------------------------------------------------------------------------
% LIST OF CONTENTS/FIGURES/TABLES PAGES
%----------------------------------------------------------------------------------------
\tableofcontents
\listoffigures
\listoftables
%----------------------------------------------------------------------------------------
% ABBREVIATIONS
%----------------------------------------------------------------------------------------
\begin{abbreviations}{ll} %
\textbf{LAH} & \textbf{L}ist \textbf{A}bbreviations \textbf{H}ere\\
\textbf{WSF} & \textbf{W}hat (it) \textbf{S}tands \textbf{F}or\\
\end{abbreviations}
%----------------------------------------------------------------------------------------
% PHYSICAL CONSTANTS/OTHER DEFINITIONS
%----------------------------------------------------------------------------------------
\begin{constants}{lr#{${}={}$}l}
Speed of Light & $c_{0}$ & \SI{2.99792458e8}{\meter\per\second} (exact)\\
\end{constants}
%----------------------------------------------------------------------------------------
% SYMBOLS
%----------------------------------------------------------------------------------------
\begin{symbols}{lll}
$a$ & distance & \si{\meter} \\
$P$ & power & \si{\watt} (\si{\joule\per\second}) \\
%Symbol & Name & Unit \\
\addlinespace
$\omega$ & angular frequency & \si{\radian} \\
\end{symbols}
%----------------------------------------------------------------------------------------
% DEDICATION
%----------------------------------------------------------------------------------------
\dedicatory{For my family}
\end{document}
%----------------------------------------------------------------------------------------
% THESIS CONTENT - CHAPTERS
%----------------------------------------------------------------------------------------
\mainmatter
\pagestyle{thesis}
\include{Chapters/Introduction}
%\include{Chapters/Chapter1}
If I compile main.tex (with PDFLatex, I also did it with Latex and PDFTex) it doesn't return me any error, but when I look at the PDF it doesn't print the Introduction.
So I was watching to the Introduction.tex:
% Chapter 1
\chapter{Chapter Title Here} % Main chapter title
\label{Chapter1} % For referencing the chapter elsewhere, use \ref{Chapter1}
%----------------------------------------------------------------------------------------
% Define some commands to keep the formatting separated from the content \newcommand{\keyword}[1]{\textbf{#1}} \newcommand{\tabhead}[1]{\textbf{#1}} \newcommand{\code}[1]{\texttt{#1}} \newcommand{\file}[1]{\texttt{\bfseries#1}} \newcommand{\option}[1]{\texttt{\itshape#1}}
%----------------------------------------------------------------------------------------
\section{Welcome and Thank You} Welcome to this \LaTeX{} Thesis Template, a beautiful and easy to use template for writing a thesis using the \LaTeX{} typesetting system.
If you are writing a thesis (or will be in the future) and its subject is technical or mathematical (though it doesn't have to be), then creating it in \LaTeX{} is highly recommended as a way to make sure you can just get down to the essential writing without having to worry over formatting or wasting time arguing with your word processor.
\LaTeX{} is easily able to professionally typeset documents that run to hundreds or thousands of pages long. With simple mark-up commands, it automatically sets out the table of contents, margins, page headers and footers and keeps the formatting consistent and beautiful. One of its main strengths is the way it can easily typeset mathematics, even \emph{heavy} mathematics. Even if those equations are the most horribly twisted and most difficult mathematical problems that can only be solved on a super-computer, you can at least count on \LaTeX{} to make them look stunning.
And if I complie it I have some errors:
Undefined control sequence \chapter
Missing \begin{document}. \chapter{C
Undefined control sequence \section
I tryed to put the \begin{document} but I still have the same errors on the undefined control sequence and other errors like
The font size command \normalisize si not defined:there is probably something wrong with the class file.
Can someone help me, please? Thanks!
If on line 13 you remove the ) and move the \end{document} statement on line 183 to the end of the main, it will compile properly.

Resources