I am trying to get multiple bar charts (4 per page) in a LaTeX document. The issue is with the title and label text of some charts. It's showing results of a survey, some questions had long text and response text. Is there a way to get a tikz chart to 'automagically' line break/wrap the text of questions or responses? I've tried manually adding \\ but that doesn't work and is problematic because I am using a macro from spreadsheet to programatically create the TeX code anyway so can't necessarily manually add \\ or other break characters. It would be ideal if PGF/TikZ/LaTeX could automatically wrap text to make it fit.
Here's an MWE without showing the 4 charts per page but the problem is still evident. Any help would be appreciated. Thanks.
\documentclass[a4paper,11pt]{article}
\usepackage{fancyhdr}
\usepackage{graphicx}
\usepackage{setspace}
\usepackage[margin=2cm,bmargin=1.3cm,footskip=5cm,headsep=0.3cm,landscape]{geometry}
%\usepackage[utf8]{inputenc} % caused compilation errors!
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{subcaption}
\usepackage{booktabs}
\makeatletter
\makeatother
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{width=7cm,compat=1.8}
\usepackage{pgfplotstable}
\usetikzlibrary{patterns}
\begin{document}
\pagestyle{fancy}
\makeatletter
\g@addto@macro@floatboxreset\centering % automatically center floats
\makeatother
\tikzset{
hatch distance/.store in=\hatchdistance,
hatch distance=10pt,
hatch thickness/.store in=\hatchthickness,
hatch thickness=2pt
}
\makeatletter
\pgfdeclarepatternformonly[\hatchdistance,\hatchthickness]{flexible hatch}
{\pgfqpoint{0pt}{0pt}}
{\pgfqpoint{\hatchdistance}{\hatchdistance}}
{\pgfpoint{\hatchdistance-1pt}{\hatchdistance-1pt}}%
{
\pgfsetcolor{\tikz@pattern@color}
\pgfsetlinewidth{\hatchthickness}
\pgfpathmoveto{\pgfqpoint{0pt}{0pt}}
\pgfpathlineto{\pgfqpoint{\hatchdistance}{\hatchdistance}}
\pgfusepath{stroke}
}
\begin{tikzpicture}
\newcommand\qText{My school provides me with information about my next steps, for example, choosing qualifications for the futue, going to university or other education and training options like apprenticeships, or finding a job.}
\newcommand\resA{Yes, I received the right amount of information that was helpful}
\newcommand\valA{48}
\newcommand\resB{Yes, but it was too much information and was not helpful}
\newcommand\valB{23}
\newcommand\resC{Yes, but there wasn’t enough information that was helpful}
\newcommand\valC{29}
\newcommand\resD{No, I haven't received any information}
\newcommand\valD{0}
\newcommand\resE{}
\newcommand\valE{0}
\newcommand\ncount{305}
\begin{axis}[
axis on top,
height=5cm,
xmin=0,
%width=\textwidth,
bar width=0.6cm,
%ymajorgrids, tick align=inside,
enlarge y limits=true,
axis x line=bottom,
axis y line=left,
y axis line style={opacity=0},
ytick=data,
%tickwidth=0pt,
enlarge x limits=false,
title={`\textbf{\qText}'},
xbar,
xlabel={% of Respondents},
symbolic y coords={{\resE}, {\resD}, {\resC}, {\resB}, {\resA}},
%ytick=data,
nodes near coords, nodes near coords align={horizontal},
]
\addplot[draw=blue!45, samples=100,
pattern=flexible hatch,
pattern color=blue!45] coordinates {(\valA,{\resA}) (\valB,{\resB}) (\valC,{\resC}) (\valD,{\resD}) (\valE,{\resE})};
\end{axis}
\end{tikzpicture}
\end{document}

\makeatotheris a confusing thing for LaTeX novices like me as often the commands seem to make no sense. Thanks again. – tornadof3 Nov 20 '21 at 09:50\makeatlettermeans: "make the @ a letter" (which can be important, since you would normally not be able to use this character, because it is exactly not considered a letter by LaTeX).\makeatotherthen means: "make the @ this other strange thing again, just like before". Just a mnemonic bridge ... See this question for more information. – Jasper Habicht Nov 20 '21 at 10:03