What I want is a legend that also includes a table of data related to each legend item.

The obvious way I see to do this is to build an attribute table that includes a column with legend info. But how to retrieve the legend information?

What I have succeeded in doing is to at least get the colour right. I did this by manually copying the colours from the (rule-based) layer styling to a collection of conditional formatting rules in the associated layer (in practice a virtual layer with a column dedicated to replicated colour).

This all works fine and produces exactly what I want in this case. But it involves a significant amount of manual work. And it won't automatically update if the styling rules in the underlying layer are modified. Yet it seems ripe for automation if only I could figure out how. And what about other legend information besides colours?

1 Answer 1


You want legend and attribute table information. It is a good idea to do it in an attribute table but what I will do is to use the legend it self for this.

In the layout add a legend item. Filter it out to get only the thing you want to keep. Since QGIS 3.14 you can edit the legend text and symbol in the layout to add rules or show attribute table information. It will not be shown as a table but with line jumps, space and dash you can make it look like one.

For each feature on your legend, you have to add an expression. This question give you one example, if you give more information on what you want to see in the legend I could adapt a formula.

  • Although this is a partial solution, it doesn't quite work for me. I need a table, so that headers, column widths, etc. are taken care of. I produce many outputs using the Atlas feature as well as scripting, so I can't count on one table arrangement working in each case.
    – Jonathan
    Jul 6, 2022 at 4:54
  • Can you show what is the content of one of your table ? Jul 6, 2022 at 12:32
  • Here is a link to a PDF produced from one page of an atlas. The table at the top of the page has 4 columns: the legend colour, the fire type, area and percentage.
    – Jonathan
    Jul 7, 2022 at 13:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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