Get the Category name into the URL for an entry
A Categories field can be related to several categories. So you'll either need to limit your Category field to a single Category relationship or you'll need to make some assumption in how you build your URL as to which category will appear in the URL. The simplest assumption to make will be that you will always return the first category for your URL.

Entry URL Format in the Section Settings:

gallery/{categories.one().slug}/{slug}


Entry Page URL:

http://mysite.com/gallery/category-slug/entry-slug


In the Entry URL Format setting above, you are telling your slug to return the slug of the first item in your array of categories using this line: {categories.first().slug} where categories is the handle of your Categories Relations field.

You may also want to ensure your Categories Relations field is required.